Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:38:52+00:00 2026-05-24T23:38:52+00:00

In my attempts to learn how to write Google Chrome extensions I decided to

  • 0

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).

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 doesn’t 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).

Here is my code

popup.html

<script type="text/javascript">

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<images.length; i++) {
            chrome.tabs.create({windowId: window.id, url: images[i]});
        }
    });
}

</script>

<button onclick="getImages();">Open images</button>

contentscript.js

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<images.length; i++) {
                urls.push(images[i].src);
            }
            console.log(urls);
            response(urls);
        }
    }
);

Anyone have any ideas why this might be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:38:52+00:00Added an answer on May 24, 2026 at 11:38 pm

    When you open the new window, it gets focus, thereby the popup loses focus. Normally, Chrome closes an extension popup when it loses focus, but keeps it open when you’re inspecting it with WebInspector. It seems that with the popup page, your images list variable gets killed.

    3 ideas out of many more to fix this:

    • Instead of one URL, give an array of URLs to the windows.create() function. (best solution)
    • Create the window without giving it focus (add "focused ": false to the object given to the create function) and only give it focus when creating the last tab.
    • Open the tabs from the content script or a background page.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to JavaScript and making only my first attempts to learn.
I'm trying to write a Date class in an attempt to learn C++. I'm
I'm ploughing ahead in my attempts to learn Mootools (damn, I miss Consider Open's
I am still trying to learn Java and decided to take it 1 step
After being frustrated in my attempts to learn the arcana that is ASP.NET, I
Upon suggestion of using Ajax for an html page, I decided to attempt to
in my attempt to learn a bit faster the use of spring and hibernate
In an attempt to learn to use PInvoke in C#, I'm a little unsure
In an attempt to learn C#, I am trying to develop Picasa Like Application
My attempts to query MySQL from PHP with a create statement of a store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.