3

I'm creating an extension that performs an action when a certain URL is clicked, redirected, or entered via Address Bar, but I want the extension to appear smooth by not having the tab appear at all.

I am using

chrome.webNavigation.onBeforeNavigate.addListener()

chrome.webRequest.onBeforeRedirect.addListener()

But these methods still briefly open the tab before closing it again (which is part of my extension's function.)

Any suggestions on preventing the tab from being opened at all (or at least delay the tab from opening)?

  • 1
    In [`chrome.webRequest`](https://developer.chrome.com/extensions/webRequest), `onBeforeRedirect` "does not allow you to modify or cancel the request". On the other hand, `onBeforeRequest` can be called synchronously and "can be used to cancel". See [this part](https://developer.chrome.com/extensions/webRequest#subscription). – Teepeemm Aug 05 '15 at 01:02
  • Thanks for the reply! Suppose I use `onBeforeRequest` to cancel the request. Would Chrome need to open a tab first, or does the request begin before the tab is opened? – user3427797 Aug 05 '15 at 17:01
  • @Teepeemm Just came across another post asking the same question (but no replies) http://stackoverflow.com/questions/26238516/chrome-extension-webrequest-redirect-to-existing-tab-without-opening-new-tab, onBeforeRequest still might not prevent the tab from being opened. – user3427797 Aug 05 '15 at 17:03
  • It looks like that may be the way to start, and read the part I linked to about returning a `webRequest.BlockingResponse`. I've never actually used `onBeforeRequest`, so I'm not exactly sure. (In other news, StackOverflow answers are supposed to be answers only, and not "did you figure this out?" You should delete the answer you left.) – Teepeemm Aug 05 '15 at 19:19

0 Answers0