Bonjour Gurus,我想创建一个像网络爬虫一样的 chrome 扩展。“标签”按钮应该:打开标签>执行脚本>关闭标签但目前,选项卡已创建,但“执行脚本”和“删除”被忽略,我错过了什么???我认为这是一个非常简单的功能,但我对 chrome.extensions 还是很陌生。希望你会有美好的一天。问候。神经网络。[app.js]var stock;chrome.runtime.onMessage.addListener(function(request){ stock = request; $.get('https://myweb.com/GetData.php?THEDATA=' + stock, function(data) { });});$('#tab').click(function(){ chrome.tabs.create({ url: 'https://stackoverflow.com/' }, function(tab) { chrome.tabs.executeScript(tab.id, { code : "chrome.runtime.sendMessage(mycommand);" }, () => chrome.runtime.lastError); chrome.tabs.remove(tab.id); });});[弹出窗口.html]<h1>MYtest</h1><button id="tab">Open Tab</button><script src="js/jquery.js"></script><script src="js/app.js"></script>[manifest.json]{ "manifest_version": 2, "name": "TestJB", "description": "TESTDESC", "version": "1.0", "permissions": [ "http://*/*", "https://*/*", "tabs", "activeTab", "alarms", "clipboardRead", "clipboardWrite", "bookmarks", "contextMenus", "contentSettings", "downloads", "history", "nativeMessaging", "browsingData", "proxy", "webRequest", "webRequestBlocking", "cookies", "webNavigation", "storage", "tabCapture", "notifications", "<all_urls>", "unlimitedStorage", "debugger" ], "browser_action": { "default_icon": "img/icon_128.png", "default_popup": "popup.html" }, "icons": { "128" : "img/icon_128.png" }}
1 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
好的,这对我有用。
[app.js]
var stock;
chrome.runtime.onMessage.addListener(function(request)
{
stock = request;
$.get('https://myweb.com/GetData.php?THEDATA=' + stock, function(data)
{
});
});
$('#tab').click(function()
{
chrome.tabs.create({ url: 'https://stackoverflow.com/', active: false }, function(tab)
{
chrome.tabs.executeScript(tab.id,
{
code : "chrome.runtime.sendMessage(mycommand);"
}, () => chrome.runtime.lastError);
chrome.tabs.remove(tab.id);
});
});
添加回答
举报
0/150
提交
取消