Merge pull request #14373 from sreimer15/master

[chrome] Fixed type of webNavigation.onBeforeNavigate.addListener
This commit is contained in:
Arthur Ozga
2017-02-10 14:24:27 -08:00
committed by GitHub
2 changed files with 29 additions and 6 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
// Type definitions for Chrome extension development
// Project: http://developer.chrome.com/extensions/
// Definitions by: Matthew Kimber <https://github.com/matthewkimber>, otiai10 <https://github.com/otiai10>, couven92 <https://github.com/couven92>, RReverser <https://github.com/rreverser>
// Definitions by: Matthew Kimber <https://github.com/matthewkimber>, otiai10 <https://github.com/otiai10>, couven92 <https://github.com/couven92>, RReverser <https://github.com/rreverser>, sreimer15 <https://github.com/sreimer15>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="filesystem" />
@@ -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<T extends WebNavigationCallbackDetails> 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<WebNavigationFramedCallbackDetails> {}
@@ -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[] | "<all_urls>";
/** Optional. */
windowId?: number;
}
+23
View File
@@ -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) => {