Open a tab in the background and get data from it - Chrome extension

Can someone please give me how to open the url in the background and how can I get the data from it. The URL I want to open is on the page where I also receive the data. I use XPath to get data. This is my code:

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 }); }); } 

});

manifest.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"] } 

]}

Background.js

 chrome.tabs.create({url: 'url_that_i_want_to_open'}); 
+4
source share
1 answer

What do you mean by "open a tab in the background"? Do you want to hide the fact from the user that in the background there is some kind of page selection? If so, I think this is not possible with the current Chrome extension APIs.

Please check this question: How to get heavy javascript pages from chrome extension

I ran into the same problem a few months ago.

If you do not care if the user finds out that a new tab / window is open, just create a new tab and do not focus on it. It's simple, check the extension documentation.

By the way, in my opinion, Xpath is not the way to go. I think CSS is better for data analysis.

Also check out this last answer: Chrome extension: how to open a link in a new tab?

+2
source

Source: https://habr.com/ru/post/1492937/


All Articles