我正在尝试让我的Chrome扩展程序注入一些javascript content_scripts,使用此前一个答案作为参考.
"name": "My Chrome Extension",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [{
"matches": ["http://pagetoinject/script/into/*"],
"js": ["contentscript.js"]
}]
Run Code Online (Sandbox Code Playgroud)
var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
(document.head||document.documentElement).appendChild(s);
s.parentNode.removeChild(s);
Run Code Online (Sandbox Code Playgroud)
(也尝试过 这个方法没有成功.)
var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
Run Code Online (Sandbox Code Playgroud)
我一直收到这个javascript错误.这是一个截图.
GET chrome-extension://invalid/
(anonymous function)
所以我基本上要完成的是mysql查询中的foreach行,它打印出来自该行数据的html.这就是我所拥有的,它不断给我一个错误的foreach.
<?php
$shots = mysql_query("SELECT * FROM shots") or die(mysql_error());
while($row=mysql_fetch_array($shots))
$data[]=$row;
foreach($shots as $data)
if (!empty($data)){
$id = $data["id"];
$shotby = $data["shot"];
$passby = $data["pass"];
$time = $data["time"];
?>
<div class="feedbody">
<div class="title"><?php echo $shotby; ?></div>
<div class="feed-data">: gets a pass from <span><?php echo $passby; ?</span> and he takes a shot!</div>
<img class="dot" src="images/dot.png" />
</div>
<?php
}
}
?>
Run Code Online (Sandbox Code Playgroud)
或类似的东西.任何人都可以帮助我指出正确的方向.我一直试图找到答案.
编辑:根据要求添加错误.
Warning: Invalid argument supplied for foreach() in /home/content/93/7527593/html/fusionboard/includes/feed.php on line 7
Run Code Online (Sandbox Code Playgroud) 我一直在搜索所有的SO并通过谷歌文档阅读,但我似乎无法找到解决方案.
我的Chrome扩展程序是注入内容脚本,我想设置一个onRequest.listenersendRequests到内容脚本.这是我以前用过的脚本onRequest.listener.问题是我出于某种未知原因不断收到此错误.
错误信息:
Uncaught TypeError: Cannot ready property 'onRequest' of undefined
contentscript.js line 1;
这是相关代码......
的manifest.json
{
"name": "Injector Extension",
"version": "1.0",
"manifest_version": 1,
"icons": { "128": "icon.png" },
"browser_action": {
"default_icon": "icon.png",
"default_title": "Injector Extension",
"default_popup": "popup.html"
},
"options_page": "options.html",
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*",
"unlimitedStorage"],
"content_scripts": [{
"matches": [" (injector specific url) "],
"js": ["contentscript.js"]
}],
"web_accessible_resources": ["js/script.js"]
}
Run Code Online (Sandbox Code Playgroud)
内容脚本
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "fromPopup") …Run Code Online (Sandbox Code Playgroud)