Chrome扩展程序在加载错误时重新加载页面 [英] Chrome extension to reload page on load error

查看:2105
本文介绍了Chrome扩展程序在加载错误时重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为不可能为此使用Greasemonkey ,我想编写一个Chrome扩展程序来重新加载



我知道如何编写Chrome扩展程序,我已经注入脚本并想出了如何与页面进行通信,所以我有关于标签如何工作以及如何构建我的清单的基本知识。



我在寻找什么事件以及如何使它适用于GET和POST请求? 解决方案

nofollow noreferrer> chrome.webNavigation.onErrorOccurred chrome.webRequest.onErrorOccurred 检测导航错误。这些API不能用于内容脚本,因此您必须添加后台页面或< 活动页面到您的扩展。



我建议使用 webNavigation API,因为这些API也可以用于事件页面(与 webRequest API不同)。 这里是一个例子,使用 chrome.tabs.reload 而不是 chrome.tabs.update 来得到你想要的。


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?

解决方案

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.

这篇关于Chrome扩展程序在加载错误时重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆