aboutsummaryrefslogtreecommitdiffstats
path: root/examples/imgur-redirect.ts
blob: 97d7c81eba8d54f572d1650c7a520eff1c88fe23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import type Browser from 'webextension-polyfill';
declare const browser: typeof Browser;
// ^ above 2 lines are optional, and only useful to allow the examples directory to not complain. The extension's monaco already defines the type of the browser global.

browser.webRequest.onBeforeRequest.addListener(
  (requestDetails) => {
    const url = new URL(requestDetails.url);
    url.host = 'imgur.010032.xyz';
    return {
      redirectUrl: url.href,
    };
  },
  { urls: ['https://imgur.com/*', 'https://www.imgur.com/*'] },
  ['blocking']
);