Skip to content

Commit

Permalink
Show all tab HTTP requests as a 'loading' status
Browse files Browse the repository at this point in the history
Suddenly found out about webextensions `webRequests` API, where you can
intercept all HTTP requests. Previously you only got status updates when
the current page fired a `window.onunload` event, which is often a long
time after the initial request to new URL is made.
  • Loading branch information
tombh committed Jun 5, 2018
1 parent 12c8a58 commit ea841fc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions webext/src/background/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default class extends utils.mixins(CommonMixin, TTYCommandsMixin) {
"Mozilla/5.0 (Android 7.0; Mobile; rv:54.0) Gecko/58.0 Firefox/58.0";
this._is_using_mobile_user_agent = false;
this._addUserAgentListener();
// Listen to HTTP requests. This allows us to display some helpful status messages at the
// bottom of the page, eg; "Loading https://coolwebsite.com..."
this._addWebRequestListener();
// The manager is the hub between tabs and the terminal. First we connect to the
// terminal, as that is the process that would have initially booted the browser and
// this very code that now runs.
Expand Down Expand Up @@ -254,4 +257,18 @@ export default class extends utils.mixins(CommonMixin, TTYCommandsMixin) {
}
return true;
}

_addWebRequestListener() {
browser.webRequest.onBeforeRequest.addListener(
(e) => {
let message;
if (e.type == 'main_frame') {
message = `Loading ${e.url}`;
this.currentTab().updateStatus('info', message);
}
},
{urls: ['*://*/*']},
["blocking"]
);
}
}

0 comments on commit ea841fc

Please sign in to comment.