How to load the URL in background page in chrome extension?

Currently i load the tabs and open the urls i need to and scrape the data from them. But that looks shabby and i don't want to open the tabs in front of the user.

There are several chrome extensions which scrape data from web sites but how do they do it without loading the page in a tab. Loading the url in iframe is not possible bcoz it has an option "CROSS-ORIGIN" in the headers.

Answers


If you mean "scrape data from web sites", you can take a look at XMLHttpRequest, it's a basic web technology and provides client functionality for transferring data between a client and a server.

Besides, when you want to do that in extension, don't forget to request cross-origin permissions.


Chrome have written their own documentation on this:

https://developer.chrome.com/extensions/background_pages

You have to register your background page in the extension manifest, and use the extension.getBackgroundPage method to read it

Example:

// React when a browser action's icon is clicked.
chrome.browserAction.onClicked.addListener(function(tab) {
var viewTabUrl = chrome.extension.getURL('image.html');
var imageUrl = /* an image's URL */;

// Look through all the pages in this extension to find one we can use.
var views = chrome.extension.getViews();
for (var i = 0; i < views.length; i++) {
var view = views[i];

// If this view has the right URL and hasn't been used yet...
if (view.location.href == viewTabUrl && !view.imageAlreadySet) {

  // ...call one of its functions and set a property.
  view.setImageUrl(imageUrl);
  view.imageAlreadySet = true;
  break; // we're done
}
}
});

HTML:

<html>
  <script>
    function setImageUrl(url) {
      document.getElementById('target').src = url;
    }
  </script>

  <body>
    <p>
    Image here:
    </p>

    <img id="target" src="white.png" width="640" height="480">

  </body>
</html>

Need Your Help

Binding a ControlTemplate's Button's Content and Command Parameter Property

c# wpf xaml data-binding itemscontrol

Okay, this is probably something pretty simple that I'm not doing quite right. I am just now learning how to add items dynamically using an ItemsControl as shown below.

Floating action button hidden behind navigation drawer

android android-coordinatorlayout floating-action-button

I am trying to ads a fab to my fragment but it is hidden behind the navigation bar. The issue is that the appear layout is interested he activities and the scroll behavior is set to the frame layo...