Chrome extension to reload page on load error

混江龙づ霸主 提交于 2019-12-21 02:30:37

问题


Because it isn't possible to use Greasemonkey for this, I want to write a Chrome extension that will reload a page if it initially failed to load.

I know how to write a Chrome extension, I've already injected scripts and figured out how to communicate with pages, so I have basic knowledge of how tabs work and how to build my manifest.

What events am I looking for and how can I make it work for both GET and POST requests?


回答1:


Use chrome.webNavigation.onErrorOccurred or chrome.webRequest.onErrorOccurred to detect navigation errors. These APIs cannot be used in a content script, so you have to add a background page or event page to your extension.

I recommend to use the webNavigation API because these can also be used with event pages (unlike the webRequest API). Here is an example, use chrome.tabs.reload instead of chrome.tabs.update to get what you want.



来源:https://stackoverflow.com/questions/23724668/chrome-extension-to-reload-page-on-load-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!