0

Hi I am working on a Google Chrome extension for educational purposses. How I can load JavaScript script to have access to the page.

Here is my loader.js:

s = document.createElement("script");
s.src = chrome.extension.getURL("src/content_script.js");

s.onload = function(){
   this.remove();
}

document.head.appendChild(s);

and here is my content_script.js:

var formats = ytplayer.config.args.raw_player_response.streamingData.formats;
console.log("YT extension loaded!");

Problem is that I get:

Uncaught TypeError: chrome.extension.getURL is not a function at loader.js:2:26

Can someone give me suggestions on what the problem might be?

Thanks in advance!

DNNikolov
  • 26
  • 7
  • It's chrome.runtime.getURL. See also [an alternative way](https://stackoverflow.com/a/46870005). – wOxxOm Jun 10 '22 at 14:17
  • Use `chrome.runtime.getURL` – Iván Nokonoko Jun 10 '22 at 14:18
  • `chrome.extension.getURL` is deprecated, as mentioned above use `chrome.runtime.getURL` – Hef Jun 10 '22 at 18:52
  • Hi, the chrome.extension.getURL seems to work so if someone actualy answer the question via the answer option will be nice. If you do please provide more info on where it is stated that crhome.extension.getURL is depricated. – DNNikolov Jun 13 '22 at 08:00
  • Firstly, it is 100% chrome.runtime.getURL() in manifest v3. Secondly, why are you injecting the content script into the page? Does it need to run in page context? You need to share your manifest because the script alone is not sufficient to determine the problem. – Jridyard Nov 07 '22 at 16:05

1 Answers1

0

According to official Chrome documentation, the chrome.extension.getUrl method has been deprecated as of Chrome 58. Moving forward, use the chrome.runtime.getUrl method to achieve the same results.

chrome.extension.getUrl may still work, however when migrating to Manifest V3 chrome will not allow you to load an extension in the browser using the deprecated extension implementation.

wh-dev
  • 537
  • 5
  • 18