JS get varible defined in script tag (Google Extension)
问题 I've got a small problem. I want to read a var defined inside tag in DOM. <script id="foo"> var x = 1 </script> I can access it via: var script = document.querySelector("#foo"); But then what? Of course var x_value = script.x or var x_value = script.outerHTML.x doesn't work. So how can I get x's value then? Thanks for your help! 回答1: Content script runs in isolated world so it cannot access the page variables directly. a literal numeric value can be extracted with a regexp: var scriptText =