mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Merge pull request #15380 from epicgirl1998/master
chrome: Really fix chrome.webNavigation event filtering
This commit is contained in:
Vendored
+5
-4
@@ -7106,12 +7106,13 @@ declare namespace chrome.webNavigation {
|
||||
transitionQualifiers: string[];
|
||||
}
|
||||
|
||||
interface WebNavigationRequestFilter extends chrome.webRequest.RequestFilter {
|
||||
/** fulfills the webRequest.RequestFilter interface even though it is under web navigation **/
|
||||
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 WebNavigationEvent<T extends WebNavigationCallbackDetails> extends chrome.events.Event<(details: T) => void> {
|
||||
addListener(callback: (details: T) => void, filters?: WebNavigationRequestFilter): void;
|
||||
addListener(callback: (details: T) => void, filters?: WebNavigationEventFilter): void;
|
||||
}
|
||||
|
||||
interface WebNavigationFramedEvent extends WebNavigationEvent<WebNavigationFramedCallbackDetails> {}
|
||||
@@ -7221,7 +7222,7 @@ 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[] | RegExp[] | "<all_urls>";
|
||||
urls: string[];
|
||||
|
||||
/** Optional. */
|
||||
windowId?: number;
|
||||
|
||||
@@ -171,7 +171,7 @@ function catBlock () {
|
||||
["blocking"]);
|
||||
}
|
||||
|
||||
// webNavigation.onBeforeNavigate.addListener example similar api to onBeforeRequest but without extra spec
|
||||
// webNavigation.onBeforeNavigate.addListener example
|
||||
function beforeRedditNavigation() {
|
||||
chrome.webNavigation.onBeforeNavigate.addListener(function (requestDetails) {
|
||||
console.log("URL we want to redirect to: " + requestDetails.url);
|
||||
@@ -180,18 +180,10 @@ function beforeRedditNavigation() {
|
||||
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"]});
|
||||
alert("Were you trying to go on reddit, during working hours? :(")
|
||||
},{url: [
|
||||
{hostSuffix: ".reddit.com"}
|
||||
]});
|
||||
}
|
||||
|
||||
// for chrome.tabs.InjectDetails.frameId
|
||||
|
||||
Reference in New Issue
Block a user