Firefox Addon displays an array with blank objects after using querySelectorAll

I am currently in the process of developing my first Firefox add-on using the SDK.

Specifically, I am focusing on interaction with the Amazon website at the moment.

After entering a search query and viewing the results, I aim to retrieve a list of all the search results.

I have successfully identified the list containing the complete search results for the initial page (16 elements).

The command

document.querySelectorAll('ul#s-results-list-atf li.s-result-item')

works flawlessly in the Firefox console when using Firebug.

However, when executing it in a Firefox add-on script, it returns a list of 16 empty objects.

Does anyone have insights into why this issue is occurring?

UPDATE: Here is the complete code:

main.js:

var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var pageMod = require("sdk/page-mod");
var self = require("sdk/self");
var data = self.data;

var button = null;
var hoverState = 0;

/*************/

/*
pageMod.PageMod({

  include: "*.mozilla.org",
  contentScriptFile: [data.url("jquery-1.10.2.min.js"), data.url("content.js")]

});
*/


// Event listener for tab content loads.
tabs.on('ready', function(tab) {
  
    var worker = tab.attach({
        contentScriptFile: [data.url("jquery-1.10.2.min.js"), data.url("content.js")]
    });

  if (tab.url.indexOf("www.amazon.de") > -1) {

      button = buttons.ActionButton({
        id: "mm1-productIdCatcher",
        label: "Enable Id Catcher",
        icon: {
            "16": "./icon-16.png",
            "32": "./icon-32.png",
            "64": "./icon-64.png"
        },
            onClick: function(state) {
                // Functionality to be added
            }
        });

        worker.port.emit("message", "+++ amazon.de detected +++");

  }
  else {
      if(button != null) {
          button.destroy();
          hoverState = 0;
      }

  }

});

content.js:

self.port.on("message", function(message) {
  console.log(message);
});

self.port.on("enable", function() {

    console.log("disabling...");


});

self.port.on("disable", function() {

    console.log("enabling...");

    var queryList = document.querySelectorAll('ul#s-results-list-atf li.s-result-item');

    console.log("queryList: ", queryList
    console.log("queryList[0]: ", queryList[0]);

     var query_0 = document.querySelector("#result_0");

    console.log("query_0: ", query_0);

    console.log("title: ", document.title);

});

And the output:

console.log: mm1-getproductid: disabling...
console.log: mm1-getproductid: enabling...
console.log: mm1-getproductid: queryList:  {"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{}}
console.log: mm1-getproductid: queryList[0]:  {}
console.log: mm1-getproductid: query_0:  {}
console.log: mm1-getproductid: title:  Search Results on Amazon.de for: qivicon

When using

document.querySelectorAll('ul#s-results-list-atf li.s-result-item')

in the Firefox console, the following result is obtained

NodeList[li#result_0.s-result-item, li#result_1.s-result-item, li#result_2.s-result-item, li#result_3.s-result-item, li#result_4.s-result-item, li#result_5.s-result-item, li#result_6.s-result-item, li#result_7.s-result-item, li#result_8.s-result-item, li#result_9.s-result-item, li#result_10.s-result-item, li#result_11.s-result-item, li#result_12.s-result-item, li#result_13.s-result-item, li#result_14.s-result-item, li#result_15.s-result-item]

Answer №1

From what I can gather, it seems that only the function console.log is displaying the elements as if they are empty. The additional code in the add-on should still be able to manipulate DOM elements without any issues.

I have a feeling that this issue may be related to the way content scripts interact with page scripts, but I must admit that I am not entirely sure about the specifics myself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with adjusting the width of an absolutely positioned image using animation

Currently, I am using jQuery version 10.4.2 and I am trying to smoothly scale up an image that is absolute positioned. However, despite not encountering any errors with the code below, the animation does not happen as expected. Instead, the image suddenly ...

What is the best way to locate every object based on its ID?

Currently, I am facing an issue where I have a list of IDs and I need to search for the corresponding object in the database. My tech stack includes Nodejs, Typescript, TypeORM, and Postgres as the database. The IDs that I am working with are UUIDs. ...

Struggling to integrate the c3 chart library with Angular, encountering loading issues

I've been attempting to utilize the c3 angular charts, but unfortunately nothing is displaying on my page. Despite checking for console errors and following a tutorial, I still can't seem to get anything to show up. I have cloned the git repo an ...

Modifying CSS classes using conditional statements and loops

var first_left = ['Photo', 'Info', 'Question 1', 'Question 2', 'Question 3', 'Question 4', 'Question 5']; var names = ['Abuela', 'Abuelo', 'Oma']; functio ...

Using JavaScript to iterate through user input and generate an array of objects

I am attempting to iterate over input elements inside a div in order to generate an array of objects. <div id="time"> <input type="text" name="from" placeholder="12:00 AM" /> <input type="text" name="to" placeholder="12:30 AM" /> & ...

Dealing with function scoping problems and transitioning to Arrow Functions

Currently, I am delving into the world of arrow functions and attempted to convert my code snippet below. Unfortunately, I have encountered a scope issue with funcCall and enterKey. My intuition tells me that utilizing an arrow function could potentially ...

Refreshing the child component based on the child's action and sending information to the parent in a React application

Within my Parent Component, I am utilizing an Ajax call to populate two children Components. C1 requires the data only once, while C2 has the ability to fetch additional data through subsequent Ajax calls and needs to render accordingly. I find it more co ...

Tips for transferring objects between AngularJS directives

Is it possible to access an object named foo that is defined/instantiated inside the link function of directive A from the link function of another separate directive? ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

arranging objects based on the distance between them

Here is a JSON array I am working with: var details = [ { 'address':'Pantaloons,701-704, 7th Floor, Skyline Icon Business Park, 86-92 Off A. K. Road,Marol Village, Andheri East,Mumbai, Maharashtra 400059', 'lat':&apos ...

Utilizing the JSON.parse method in JavaScript in conjunction with an Ajax request while incorporating the escape character "\n" for new line functionality

https://jsbin.com/zuhatujoqo/1/edit?js,console Edit: json file has this line: {"pd":"ciao \\n ste"} I need to retrieve a valid JSON file through an ajax call. Then parse the result using JSON.parse. I'm confused about the behavior of t ...

Converting various forms of data into arrays using JavaScript

I have a series of forms set up like this: <div class="well"> <form> <span class="remove pull-right"><i class="fa fa-times pointer"></i></span> <div class="form-group" style="margin:0"> ...

The issue with AngularJS ng-show and $timeout functionality not functioning as expected

As a newcomer to AngularJS, I recently started an individual project utilizing ng-show and if else statements with $timeout. Despite my efforts, I have been unable to make the answers timeout after being displayed for a few seconds. I've tried various ...

What is the best way to insert a line break into every row of the table I'm displaying?

My current project involves building a web scraper that successfully prints a table, but the formatting of the table is less than satisfactory. I've experimented with a few solutions so far: 1) const people = [...peopleList].map(personEntry => pe ...

React: Issue with applying inline styles to child components

Goal: My objective involves dynamically resizing the textarea and its parent container based on the scrollHeight of the textarea within a Main component. I also have a Button component as a child of Main for clearing text from the textarea, though that is ...

Struggles with toggling a sliding menu using JQuery

As I work on constructing a menu, I've implemented submenus that slide down upon hovering over the parent item and remain expanded when clicking on an arrow next to the parent. While the hovering functionality is working correctly, I'm encounteri ...

I am experiencing some difficulty with the GetServerDate using the JSON protocol in JQuery; it's

I am facing an issue while trying to execute a basic ajax call to fetch data from a file on a server. Even though I can access the file via the web browser and have diligently followed tutorials related to this topic, I have hit a dead end. Here is the sn ...

Make the jQuery toggle() function work like a regular radio button when selecting multiple options at a time

I have recently created two radio buttons using <i> font icons. Previously, I had successfully used the same code to create a checkbox, so I applied it to the radio buttons as well. After fixing the positioning, everything seemed fine when interactin ...

What is the best way to invoke an HTML file using a jQuery function in a JavaScript file?

When I call an HTML file from a jQuery function using require(), I am encountering an issue where I am unable to link the CSS with the HTML file. After running the file, only plain HTML is displayed without any styling. The structure of my HTML file is as ...

Enclosing sets of lists with div containers

My Objective: <ul> <li class="group4"> <ul class="group2"> <li class="first">stuff</li> <li class="last">stuff</li> </ul> <ul class="group2"> ...