Irtza.QC
Irtza.QC

Reputation: 1136

Unable to get scope in content script Firefox Addon

I am developing an addon for Firefox. In a content script file I have the line

angular.element(document.getElementById("angularAppDiv")).scope(); 

it returns null. However if I type the same line into the browser console, I get the scope object? Could someone point out what's happening and why?

Upvotes: 0

Views: 74

Answers (1)

Dmitri Pavlutin
Dmitri Pavlutin

Reputation: 19130

By default, content scripts loaded by add-ons and scripts loaded by web pages are insulated from each other:

  • content scripts can't interact directly with page scripts or access JavaScript objects they create
  • page scripts can't interact directly with content scripts or access objects they create.

What you could do is to insert this script tag from content script into the page:

document.head.innerHTML = document.head.innerHTML + '<script> console.log(angular.element(document.getElementById("angularAppDiv")).scope());</script>';

Check this link for more info.

Upvotes: 1

Related Questions