gpt4 book ai didi

javascript - 如何重定向到 chrome 中的扩展页面?

转载 作者:行者123 更新时间:2023-12-05 06:44:23 25 4
gpt4 key购买 nike

在我的 web 应用程序中,我想放置一个代码,在执行时将当前选项卡重定向到某个扩展页面?

如果我这样做

window.location = 'chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj';

它将我重定向到不在那个特定扩展页面上的“about://blank”。

enter image description here

谁能帮我实现同样的目标。

最佳答案

首先,您需要将 chrome 扩展程序的所有资源放入 web_accessible_resources

您还需要触发重定向行为。您可以使用 content_scripts 执行此操作,并且您需要特定域的权限

最终你会得到像这样的ma​​infest.json:

    "permissions": [
"*://example.com/*"
],
"content_scripts": [{
"js": ["injection.js"],
"matches": ["*://www.example.com/*", "*://example.com/*"]
}],
"web_accessible_resources" : [
"index.html",
"main.js",
"favicon.ico"
],

injection.js 像:

location = 'chrome-extension://'+chrome.runtime.id+'/index.html';

关于javascript - 如何重定向到 chrome 中的扩展页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29305668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com