有人可以给我如何在后台打开网址以及如何从中获取数据。我要打开的 URL 在我也从中获取数据的页面中。我使用 XPath 来获取数据。这是我的代码:
Popup.js
chrome.tabs.query({
active: true,
currentWindow: true }, function(tabs){
if(tabs[0].url.indexOf("extranet.louvre-hotels.fr")!=-1)
{
chrome.tabs.sendRequest(tabs[0].id, {
action: "getDOM"
}, function(response)
{
chrome.tabs.getSelected(null, function(tab) {
// get response
});
});
}
});
清单.json
{
"manifest_version": 2,
"name": "SymaExtract",
"description": "SymaExtract",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"webNavigation",
"tabs",
"background",
"http://localhost/extract.php",
"http://*/*"
],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["dom.js"]
}
] }
背景.js
chrome.tabs.create({url: 'url_that_i_want_to_open'});