javascript - Why won't window.location.href work on error pages? -
i developing google chrome extension, , if user goes site doesn't exist, thiswebsitedoesnotexist.com, want extension redirect them page set me. not talking sites give 404 errors. mean sites dns server address cannot found, google chrome gives it's standard error page.
i tried using window.location.href = *link*
, doesn't change webpage. how can around this? in advance.
why won't window.location.href work on error pages?
because, in fact, being shown document data:
url internal error pages, despite address bar showing intended address. can verify devtools inspecting window.location
in error page.
data:
urls are not scriptable chrome extensions: no host permission allows inject content scripts them.
therefore, attempts programmatically inject content script changes window.location.href
(or console.log
) fail due missing permissions, , match patterns content scripts in manifest won't apply.
how can around this?
you can use chrome.tabs.update
background page navigate away error page.
to detect such error in background page, best fit use chrome.webnavigation
api, though using chrome.webrequest
api possible (careful filters, , requires broad permissions). both provide tabid
this.
Comments
Post a Comment