gpt4 book ai didi

google-chrome - 资源必须列在 web_accessible_resources list 键中,才能被扩展之外的页面加载

转载 作者:行者123 更新时间:2023-12-03 10:40:45 28 4
gpt4 key购买 nike

在检查 onUpdated.addListener 的 URL 时,我尝试了多种方法(所有记录的过程)将脚本注入(inject)特定页面。最后,下面带有“executescript”的代码似乎可以工作,但并不完美。我可以得到警报,但无法通过 getElementById/getElementsByName 找到页面的文档元素。

当我检查页面时,脚本被注入(inject)。但在错误控制台中我得到:

Denying load of chrome-extension://jfeiadiicafjpmaefageabnpamkapdhe/js/Leoscript.js. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.



list .json:

{
"name": "Leo Extension for Job Boards",
"version": "1.6",
"manifest_version": 2,
"content_security_policy": "script-src 'self'; object-src 'self'",
"description": "Leo Extension",
"background": {
"scripts": ["js/Leojshelper.js"],
"persistent": true
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/eventPage.js"],
"run_at" : "document_start"
}
],
"icons":{"48":"images/bob48.png", "128":"images/bob128.png"}, //Define any icon sizes and the files that you want to use with them. 48/128 etc.
"browser_action": {
"default_icon": "images/bob.png", // What icon do you want to display on the chrome toolbar
"default_popup": "LeoExtwatch.html" // The page to popup when button clicked.
},
"permissions": [
"tabs", "<all_urls>" // "http://*/*","https://*/*" // Cross Site Access Requests
],
"web_accessible_resources": ["js/LeoScript.js"]
}

我还授予了脚本的“web_accessible_resources”权限,但仍然没有成功。后台脚本中的代码:

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
if (tab.url.indexOf("in.yahoo") !== -1) {
chrome.tabs.update(tabId, { url: "https://login.yahoo.com/config/mail?.intl=us" });
chrome.tabs.executeScript(tabId, {
code: "document.body.appendChild(document.createElement('script')).src='" +
chrome.extension.getURL("js/LeoScript.js") + "';"
}, null);

LeoScript.js 中的代码,将被注入(inject)特定页面。

$(document).ready(function () {
alert('injected');
document.getElementById('username').value='aaaaaaa';
});

内容脚本:eventPage.js,我用来注入(inject)脚本。

var script = document.createElement('script');
script.src = chrome.extension.getURL("js/Leoscript.js");
(document.body || document.head || document.documentElement).appendChild(script);

请指出上述代码中将解决权限问题的任何更改。提前致谢。

最佳答案

编辑:

这是 web_accessible_resources 组合的工作版本和 Injection用来

manifest.json

{
"name":"Off Screen Tabs Demo",
"description":"This demonstrates Off Screen Tabs API",
"manifest_version":2,
"version":"1",
"permissions":["tabs","<all_urls>"],
"browser_action":{
"default_icon":"screen.png",
"default_popup":"popup.html"
},
"web_accessible_resources": ["js/LeoScript.js"] ,
"permissions":["tabs","<all_urls>"]
}

LeoScript.js
alert("Injected..");

popup.html
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>

popup.js *
document.addEventListener("DOMContentLoaded",function (){
chrome.tabs.executeScript( {"file": "js/LeoScript.js"});
});

如果您在运行它时仍有问题,请告诉我

关于google-chrome - 资源必须列在 web_accessible_resources list 键中,才能被扩展之外的页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13696906/

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