diff --git a/chrome/index.d.ts b/chrome/index.d.ts index cd6922f5fb..211375a3fe 100644 --- a/chrome/index.d.ts +++ b/chrome/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for Chrome extension development // Project: http://developer.chrome.com/extensions/ -// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser +// Definitions by: Matthew Kimber , otiai10 , couven92 , RReverser , sreimer15 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -7062,13 +7062,12 @@ declare namespace chrome.webNavigation { transitionQualifiers: string[]; } - interface WebNavigationEventFilter { - /** Conditions that the URL being navigated to must satisfy. The 'schemes' and 'ports' fields of UrlFilter are ignored for this event. */ - url: chrome.events.UrlFilter[]; + interface WebNavigationRequestFilter extends chrome.webRequest.RequestFilter { + /** fulfills the webRequest.RequestFilter interface even though it is under web navigation **/ } interface WebNavigationEvent extends chrome.events.Event<(details: T) => void> { - addListener(callback: (details: T) => void, filters?: WebNavigationEventFilter): void; + addListener(callback: (details: T) => void, filters?: WebNavigationRequestFilter): void; } interface WebNavigationFramedEvent extends WebNavigationEvent {} @@ -7178,7 +7177,8 @@ declare namespace chrome.webRequest { */ types?: string[]; /** A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out. */ - urls: string[]; + urls: string[] | RegExp[] | ""; + /** Optional. */ windowId?: number; } diff --git a/chrome/test/index.ts b/chrome/test/index.ts index 7788397a4c..3074b8a0c3 100644 --- a/chrome/test/index.ts +++ b/chrome/test/index.ts @@ -171,6 +171,29 @@ function catBlock () { ["blocking"]); } +// webNavigation.onBeforeNavigate.addListener example similar api to onBeforeRequest but without extra spec +function beforeRedditNavigation() { + chrome.webNavigation.onBeforeNavigate.addListener(function (requestDetails) { + console.log("URL we want to redirect to: " + requestDetails.url); + // NOTE: This will search for top level frames with the value -1. + if (requestDetails.parentFrameId != -1) { + return; + } + + let url = new URL(requestDetails.url); + let splitUrl = url.hostname.split('.'); + //` Note: Does not cover the XX.co.uk type edge case + let host = (splitUrl[(splitUrl.length -1) - 1]); + + if (host === null) { + return; + } else if (host === "reddit") { + alert("Were you trying to go on reddit, during working hours? :(") + return; + } + },{urls: ["http://*/*"], types: ["image"]}); +} + // contrived settings example function proxySettings() { chrome.proxy.settings.get({ incognito: true }, (details) => {