Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel webRequest silently in chrome extension

I'm re-posting my question from Chromium-extensions google group here.

In my extension, I want to cancel some webRequests based on url pattern. My problem is that, if I return {cancel:true} in the onBeforeRequest event listener, the browser would redirect to a page telling me that the request is blocked by some extension. But I just want to cancel the request silently(as nothing happened).

I have also tried to return {redirectUrl:""} in the onBeforeRequest event listener, the console would log an error saying that "" was not a valid URL, and a bar appeared at the bottom of the browser, saying "Waiting for extension". To dismiss that bar, I then run content script "window.stop()" in that web page. That works sometimes, but not always. So I wonder if someone has any better solution. Thanks!!

like image 974
Jun Avatar asked Sep 08 '13 13:09

Jun


People also ask

How do I send a post request extension in Chrome?

Type the url in the main input field and choose the method to use: GET/POST/PUT/DELETE/PATCH. Click on the arrow "Send" or press Ctrl+Enter. You'll see info about the response (time, size, type) and you'll be able to see the content response in the response section.

What is the API used for webRequestBlocking?

To use the webRequest API for a given host, an extension must have the "webRequest" API permission and the host permission for that host. To use the "blocking" feature, the extension must also have the "webRequestBlocking" API permission.

What is webRequest API?

# Life cycle of requests. The web request API defines a set of events that follow the life cycle of a web request. You can use these events to observe and analyze traffic. Certain synchronous events will allow you to intercept, block, or modify a request.

When to call the WebRequest function?

Needs to be called when the behavior of the webRequest handlers has changed to prevent incorrect handling due to caching. This function call is expensive. Don't call it often. Fired when an extension's proposed modification to a network request is ignored. This happens in case of conflicts with other extensions.

How to intercept a web request in chrome?

Starting from Chrome 72, an extension will be able to intercept a request only if it has host permissions to both the requested URL and the request initiator. As the following sections explain, events in the web request API use request IDs, and you can optionally specify filters and extra information when you register event listeners.

How do I use the Chrome web request API?

Use the chrome.webRequest API to observe and analyze traffic and to intercept, block, or modify requests in-flight. You must declare the "webRequest" permission in the extension manifest to use the web request API, along with the necessary host permissions.

What is the WebRequest API?

The webRequest API let extension developers intercept all network requests, pause them while they evaluated and blocked or modify them in JavaScript, and only then begin fulfilling the requests. These are quite powerful capabilities with big privacy, security, and performance implications.


1 Answers

return {redirectUrl: 'javascript:void(0)'};
like image 51
coooold Avatar answered Sep 30 '22 02:09

coooold