let/const not work in chrome extersions
Reported by
maicss...@gmail.com,
Jul 21 2017
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 Steps to reproduce the problem: 1. [let/const aa = 11] in background js 2. [let bg = chrome.extension.getBackgroundPage()] in content_scripts js 3. [console.log(bg.aa)] in content_scripts js What is the expected behavior? should get 11 in console What went wrong? what I got is undefined. code: [var aa = 11] in background js works fine Did this work before? No Chrome version: 59.0.3071.115 Channel: stable OS Version: OS X 10.12.5 Flash Version: Shockwave Flash 26.0 r0 any others ES6+ syntax are not supported?
,
Jul 21 2017
Also, chrome.extension.getBackgroundPage() is not available in the content scripts at all because it's a window object of a different *origin*: the background page has chrome-extension://*extension-id* while content scripts run in the origin of the web page like http://, https://, ftp://, file://, or (chrome:// via an unsupported command line switch).
,
Jul 22 2017
Sorry, it was popup.js, not [content_scripts]. Still the seme reason? Thanks
,
Jul 22 2017
Yes, the same applies: the popup is a different page, its script doesn't run 'inside' the background page and doesn't share its lexical environment. If you're using eslint rules to forbid vars then either add inline exclusions via comments like "// eslint-disable-line no-var" or switch to assigning the shared variables as window object properties because this is effectively the same as a global var: window.foo = "bar"
,
Jul 24 2017
@maicss: Thanks for the report!! Could you please provide us a sample extension file to test the issue from our end? Thanks!!
,
Jul 24 2017
,
Jul 25 2017
Thanks all!!! As woxxom@gmail.com said, that's my syntax error caused this problem. not chrome's bug. Anyone close this issue please? Thanks.
,
Jul 25 2017
Thank you for providing more feedback. Adding requester "sandeepkumars@chromium.org" to the cc list and removing "Needs-Feedback" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jul 25 2017
Closing this issue as per comment #7. Thanks!! |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by woxxom@gmail.com
, Jul 21 2017