Closed Bug 1276338 Opened 3 years ago Closed 3 years ago

chrome.runtime.id is undefined in content scripts

Categories

(WebExtensions :: Untriaged, defect)

49 Branch
x86_64
Windows 10
defect
Not set

Tracking

(firefox49 fixed)

RESOLVED FIXED
mozilla49
Iteration:
49.3 - Jun 6
Tracking Status
firefox49 --- fixed

People

(Reporter: serge.zarembsky, Assigned: bsilverberg)

Details

(Whiteboard: [runtime]triaged)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Steps to reproduce:

While porting our (Ghostery) code written for Chrome to Nightly build 49 with Web Extesions API support we noticed that in context script chrome.runtime.id is undefined. It is properly defined when accessed in background.js or extension popup scripts.


Actual results:

chrome.runtime.id is undefined


Expected results:

chrome.runtime.id should be equal to our extension id specified in the manifest under this key:

	"applications": {
	  "gecko": {
	    "id": "ghostery@ghostery.com"
	  }
OS: Unspecified → Windows 10
Hardware: Unspecified → x86_64
Component: Untriaged → WebExtensions
Product: Firefox → Toolkit
The code in `ExtensionContent.jsm` confirms that we do not provide this value to content scripts, and the Chrome docs do state that it is available to content scripts [2], so it sounds like something we should support. Do others agree?

[1] https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ExtensionContent.jsm#71
[2] https://developer.chrome.com/extensions/runtime
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: chrome.runtime.id is undefined in context scripts → chrome.runtime.id is undefined in content scripts
Whiteboard: [runtime]triaged
Agreed, with the minor point that it is the id of the addon stored in the addons manager, which may not correspond directly to the manifest if its absent from the manifest.
Thanks Andy. This is a very easy fix so I'm just going to bang it off.
Assignee: nobody → bob.silverberg
Status: NEW → ASSIGNED
Iteration: --- → 49.3 - Jun 6
Comment on attachment 8758402 [details]
MozReview Request: Bug 1276338 - chrome.runtime.id is undefined in content scripts, r?kmag

https://reviewboard.mozilla.org/r/56634/#review53304

::: toolkit/components/extensions/test/mochitest/test_ext_runtime_id.html:47
(Diff revision 1)
> +  yield extension.startup();
> +
> +  let backgroundId = yield extension.awaitMessage("background-id");
> +  let win = window.open("file_sample.html");
> +  let contentId = yield extension.awaitMessage("content-id");
> +  is(backgroundId, contentId, "runtime.id from background script matches id from content script");

We should check that they're both the same as the extension ID, not just that they're the same.

You can pass an ID as the second argument of `loadExtension`
Attachment #8758402 - Flags: review?(kmaglione+bmo)
Comment on attachment 8758402 [details]
MozReview Request: Bug 1276338 - chrome.runtime.id is undefined in content scripts, r?kmag

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/56634/diff/1-2/
Attachment #8758402 - Flags: review?(kmaglione+bmo)
https://reviewboard.mozilla.org/r/56634/#review53304

> We should check that they're both the same as the extension ID, not just that they're the same.
> 
> You can pass an ID as the second argument of `loadExtension`

Nice! I did not know that.
Comment on attachment 8758402 [details]
MozReview Request: Bug 1276338 - chrome.runtime.id is undefined in content scripts, r?kmag

https://reviewboard.mozilla.org/r/56634/#review53654

Looks good. Thanks!
Attachment #8758402 - Flags: review?(kmaglione+bmo) → review+
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/fx-team/rev/1b67bc89fe9a
chrome.runtime.id is undefined in content scripts, r=kmag
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/1b67bc89fe9a
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.