Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Chrome behaves differently when the popup is being inspected
    primarykey
    data
    text
    <p>In my attempts to learn how to write Google Chrome extensions I decided to write one where upon clicking a button in the popup the extension opens a new window and opens a new tab for every image on the page. Each tab's url is the src for each image. (I don't think this is particularly useful, I'm doing it merely as an exercise).</p> <p>The weird thing is that it works exactly as I would expect when I have right-clicked on the extension icon and clicked 'inspect popup'. It <em>doesn't</em> work as expected when I just use it normally. When used normally it only opens 3 or 4 of the images (even weirder is that it's a different number of images it manages to open each time).</p> <p>Here is my code</p> <p><strong>popup.html</strong></p> <pre><code>&lt;script type="text/javascript"&gt; function getImages() { chrome.tabs.getSelected(null, function(tab){ chrome.tabs.sendRequest(tab.id, {code: "getImages"}, function(images) { console.log(images); openImages(images); }); }); } function openImages(images) { chrome.windows.create({url: images[0]}, function(window) { for(var i=1; i&lt;images.length; i++) { chrome.tabs.create({windowId: window.id, url: images[i]}); } }); } &lt;/script&gt; &lt;button onclick="getImages();"&gt;Open images&lt;/button&gt; </code></pre> <p><strong>contentscript.js</strong></p> <pre><code>chrome.extension.onRequest.addListener( function(request, sender, response) { if(request.code == 'getImages') { console.log("We're in!"); var urls = []; var images = document.getElementsByTagName("img"); for(var i=0; i&lt;images.length; i++) { urls.push(images[i].src); } console.log(urls); response(urls); } } ); </code></pre> <p>Anyone have any ideas why this might be?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload