Chrome 扩展程序定时重定向
我想要实现的是让 chrome 扩展在后台运行,每分钟它都会重定向到 google.com,然后一分钟后重定向到 stackoverflow.com 等等,直到用扳手单击图标为止大多数扩展程序所在的图标。
但是我只知道如何使用重定向页面 window.location.replace("http://google.com");
我仍在学习如何开发 Chrome 扩展,只是为学习过程制作一些简单的东西。我从此教程开始学习,并尝试了一些方法,现在我想弄清楚如何让这样的东西在后台运行。
What I'm trying to achieve is make a chrome extension run in the background, and every minute it'll redirect to google.com and then a minute later redirect to stackoverflow.com and so on continuously until the icon is clicked by the wrench icon where most of the extensions are.
However I only know on how to redirect a page using
window.location.replace("http://google.com");
I'm still learning on how to develop chrome extensions, and just making some simple stuff for a learning process. I started learning from this tutorial, and tried a couple things out, and now I wanna figure out how to get something like this to work with it running in the background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
替代解决方案(我将 url 选择部分保留)。
背景.html:
Alternate solution (I am leaving url selection part out).
background.html:
您也可以只编写要注入的内容脚本,但这很简单,我只是将其存储在变量中。我建议您查看 chrome.tab API,如 Google在为开发人员记录 API 方面做得非常好。
在您的后台页面中:
在您的manifest.json中:
You could also just write a content script that you would inject, but it's easy enough that I just stored it in a variable. I would recommend looking at the chrome.tab API, as Google does a very good job of documenting their API for developers.
In your background page:
In your manifest.json: