Click here to Skip to main content
15,885,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I have a problem with my javascript.
When I run it from the developer console the code is working. When I use my code to create the extension - I receive error.



Thanks in advance!

What I have tried:

var fullOffer = document.querySelectorAll('.js-offer-proceed')[0];
var len = fullOffer.querySelectorAll('.cartlist__item');


Later I'm using fullOffer variable to extract specific data from the screen without any problem.

When I add this code as extension I receive this error:
Screenshot of the error[^]

What can be the reason to run without any problems the code in developer console, but when I store the code in .js file and import it as extension to stop working?

This is the code from the manifest file:
{
  "manifest_version": 2,

  "name": "Getting started example",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",
    "permissions": [
    "storage"
  ],
  
  
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },

  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}


I try just to create a simple alert message when I click button and the extension is working, so I expect the problem maybe it's not in the Manifest file, but not sure?
It's actually my first extension.
Posted
Updated 22-Jan-21 10:28am
v2

1 solution

Your object is null. So clearly the context causes it to not exist
 
Share this answer
 
Comments
vganchev 22-Jan-21 16:29pm    
Hi Christian,
It's not possible to be null, because when I run the whole code from the dev console, I don't get null? Also the whole script is returning all data from the screen.
If it's possible only as extension to not work this code, what can be the reason to return null when the code is executed as extension?
Richard Deeming 25-Jan-21 4:32am    
Well, the error message clearly tells you that it is null.

You keep mentioning that you're running this as an extension. Presumably you mean a browser extension? Try debugging your code - it's likely that the document your extension is looking at is not the same document that you're running the console code against.
vganchev 22-Jan-21 16:33pm    
Screenshot when I run the same code from the console: https://imgur.com/IOlkP83

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900