简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM