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 4037854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:24:02+00:00 2026-05-20T12:24:02+00:00

I have written an extension for google chrome and I have a bug I

  • 0

I have written an extension for google chrome and I have a bug I need a help solving.
what I do is using either a text selection or an input of text search for photos on flickr and then create a results tab.
The extension works most of the times. but sometimes it creates a blank tab with no results and when I repeat the same search it then shows results. I figured that it’s something to do with the html files messaging maybe something to do with them communicating. I have to say that I always receive the results from flickr so that the request/responce with flickr works ok. Sometimes the error happens when I play with other tabs or do something on other tabs while waiting for results. can you please help me figure out where’s the fault?

the background file:

function searchSelection(info,tab){
var updated;
    if(info.selectionText==null){
        var value = prompt("Search Flickr", "Type in the value to search"); 
        updated=makeNewString(value);
    }
    else{
        updated=makeNewString(info.selectionText);
    }
    var resultHtml;
    var xhReq = new XMLHttpRequest();
    xhReq.open(
    "GET",
    "http://api.flickr.com/services/rest/?method=flickr.photos.search&text="+updated+
    "&api_key=a0a60c4e0ed00af8d70800b0987cae70&content_type=7&sort=relevance&per_page=500",
    true);
    xhReq.onreadystatechange = function () {

        if (xhReq.readyState == 4) {
            if (xhReq.status == 200) {
            chrome.tabs.executeScript(tab.id, {code:"document.body.style.cursor='auto';"});
                var photos = xhReq.responseXML.getElementsByTagName("photo");
                if(photos.length==0){
                    alert("No results found for this selection");
                    chrome.tabs.executeScript(tab.id, {code:"document.body.style.cursor='auto';"});
                    return;
                }
                var myJSPhotos=[];
                for(var i=0; i<photos.length; i++){
                    var data={"id":photos[i].getAttribute("id"),"owner":photos[i].getAttribute("owner"),
                                "secret":photos[i].getAttribute("secret"),"server":photos[i].getAttribute("server"),
                                "farm":photos[i].getAttribute("farm"),"title":photos[i].getAttribute("title")};
                    myJSPhotos[i]=data;
                }

                    chrome.tabs.create({"url":"results.html"},function(thistab){
                    var port= chrome.tabs.connect(thistab.id);
                    port.postMessage({photos:myJSPhotos});
                });

            }
        };
    };
    xhReq.send(null);
    chrome.tabs.executeScript(tab.id, {code:"document.body.style.cursor='wait';"});

}


var context="selection";
var id = chrome.contextMenus.create({"title": "search Flickr", "contexts":[context,'page'],"onclick":searchSelection});

results html: has only a reference to the js file res.js

res.js :

chrome.extension.onConnect.addListener(function(port) {
  port.onMessage.addListener(function(msg) {
//*****//
    var photos=msg.photos;
    createPage(photos);

  });
});

I have to mention that when the tab is empty if I put alert on the //*****// part it won’t
fire.
but when I print out the photos.length at the tab create call back function part it prints out the correct result.

  • 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-20T12:24:03+00:00Added an answer on May 20, 2026 at 12:24 pm

    Try to set "run_at":"document_start" option for your res.js in the manifest.

    I think callback from chrome.tabs.create is fired right away without waiting for page scripts to be loaded, so you might try something like this instead:

    //global vars
    var createdTabId = null;
    var myJSPhotos = null;
    
    xhReq.onreadystatechange = function () {
    
        //assign myJSPhotos to a global var
    
        chrome.tabs.create({"url":"results.html"},function(thistab){
            createdTabId = thistab.id;
        });
    }
    
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
        if(changeInfo.status == "complete" && tab.id == createdTabId) {
            createdTabId = null;
    
            //now page is loaded and content scripts injected
            var port = chrome.tabs.connect(tab.id);
            port.postMessage({photos:myJSPhotos});
    
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an extension in Google Chrome that opens a tab to a
I have written a Chrome extension that adds a char counter to some input
I have written some C/C++ extension modules for PHP, using the 'old fashioned way'
I've written an extension for Google Chrome that will be released with the next
I have written a C extension library for PG, using V1 calling convention. My
I've written a Google Chrome extension (https://chrome.google.com/webstore/detail/fhmcfamnddgoloojehbeokifhaiiebfm), and I'm noticing that the extension works
I have written a very simple Chrome extension. It consists of this background page:
I have written a Python extension library in C and I am currently using
I have written an extension method for string manipulation. I'm confused what should I
I have written a following code to get just the file name without extension

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.