Background.js Doesn't Find Content Injected with Content Script

前端 未结 1 1587
故里飘歌
故里飘歌 2021-01-28 23:23

My Chrome extension has a Content-Script that injects a custom DIV into the current page. This part works.

But then, the extension also has a right-click Context Menu, w

相关标签:
1条回答
  • 2021-01-28 23:29

    Wrong document in

    var divHTML = document.getElementById('infoDiv').innerHTML;
    

    Please read the Architecture Overview first. Your background script is executed in a separate HTML document, and as such won't "see" the page in the tab.

    You'll need to pass the value to the content script to do something with a visible page. You'll probably need Messaging.

    0 讨论(0)
提交回复
热议问题