如何使用 Google Chrome 扩展程序重定向到 URL内容脚本? [英] How do I redirect to a URL using a Google Chrome Extension & Content Script?

查看:37
本文介绍了如何使用 Google Chrome 扩展程序重定向到 URL内容脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个 Google Chrome 扩展程序,它会测试某些模式,如果找到,会将它们重定向到一个新的 URL.

I'm currently building a Google Chrome extension which tests for certain patterns and if found, redirects them to a new URL.

我已经通过内容脚本完成了模式检查,现在我不确定如何继续完成重定向.有什么建议吗?

I've gotten the pattern checking done via a content script, and now I'm not sure how can I proceed with getting the redirect done. Any suggestions ?

推荐答案

将重定向 url 从内容脚本发送到后台页面:

Send redirect url from a content script to a background page:

chrome.runtime.sendMessage({redirect: "http://redirect"});

在会导致重定向的后台页面更新选项卡的 url 中:

In a background page update tab's url which would cause redirect:

chrome.runtime.onMessage.addListener(function(request, sender) {
    chrome.tabs.update(sender.tab.id, {url: request.redirect});
});

这篇关于如何使用 Google Chrome 扩展程序重定向到 URL内容脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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