Firefox, new to extension, some question

Hello, i’m new here. I want to develop a firefox extension for my site.
I started to create files, it’s all ok.But for now, i want to work step by step.I tried to add a alert when page loaded

function startup(){
	var x = "done !";
	alert(x);
}
window.addEventListener("load", startup, false);

Code is in borderify:

  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "js": ["borderify.js"]
    }
  ]

But nothing happens.

If i resolve that, next step will be:

  • click on a id when page loaded completly
  • inspect an element and extract something.
  • etc

I want learn to develop extension, final step is extract from a player loaded in iframe, url of video link directly (video.mp4), for now is little hard.

Sorry for my eng. Thank u !

Pretty much whenever you use the load event, you should also consider the document.readyState:

document.readyState === 'complete' ? startup() : window.addEventListener('load', startup);

Since (unless you change it via run_at) content_scripts are run after the load event fired, you’ve already missed the load event in your code.

I think what you want is to wait for the document to be loaded using: document.addEventListener('DOMContentLoaded', () => {/* your code here */}).

But for your ultimate goal - extracting link from iframe - you cannot use content script running in the parent document (you cannot access iframe due to security restrictions).

You will need to either inject your content script into that iframe (or all frames), or intercept the webRequest:

Yes, but the stuff with document.readyState applies to DOMContentLoaded as well.

If you happen to want to get YouTube video URLs, a browserifyed version of ytdl-code works much better.