1
在我的谷歌浏览器扩展程序中,用户单击链接并且必须自动登录页面。
流程必须如下所示:用户单击GC Extension中的链接,脚本将采用所有必需的参数并发送到新打开的选项卡。
有我的脚本必须插入传递的参数,并采取一些行动。
但我不明白,我怎么能从GC扩展脚本传递变量到新打开的选项卡?
这里是我的manifest.json将Chrome扩展程序中的变量传递给打开的选项卡
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
"content_scripts": [
{
"js": [ "window/content.js"],
"matches": [
"https://steamcommunity.com/login/home/?goto=",
"http://steamcommunity.com/*",
"https://steamcommunity.com/*"
]
}
],
"background": {
"scripts": [
"./scripts/back.js"
]
},
"web_accessible_resources": [
"popup.js",
"window/content.js"
],
"permissions": [
"activeTab",
"tabs",
"<all_urls>",
"cookies",
"declarativeContent"
]
我到目前为止已经试过在main.js使用此:
chrome.tabs.executeScript(
tab1.id,
{code: "var test =" + test
allFrames: true
},
{file: "../popup.js"},)
})
但当点击执行,打开脚本新的标签,执行我写的所有内容,但看不到变量'test'。
当指定'file'和'code'时,executeScript显然只使用'file'。使用消息传递或简单地嵌套executeScript:外部运行'代码',并在其回调内部运行'文件'。 – wOxxOm
脚本将在扩展的范围内执行,这使得向页面写入任何内容非常困难。我建议只使用'localStorage'。请记住,这会在两次会话之间持续存在,这可能是一个专业或一个骗局,具体取决于你想要做什么。 – Archer