chrome.runtime.id is undefined in content scripts

RESOLVED FIXED in Firefox 49

Status

()

Toolkit
WebExtensions: Untriaged
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: Serge, Assigned: bsilverberg)

Tracking

49 Branch
mozilla49
x86_64
Windows 10
Points:
---

Firefox Tracking Flags

(firefox49 fixed)

Details

(Whiteboard: [runtime]triaged)

MozReview Requests

()

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
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"
	  }
(Reporter)

Updated

2 years ago
OS: Unspecified → Windows 10
Hardware: Unspecified → x86_64

Updated

2 years ago
Component: Untriaged → WebExtensions
Product: Firefox → Toolkit
(Assignee)

Comment 1

2 years ago
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

Comment 2

2 years ago
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.
(Assignee)

Comment 3

2 years ago
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
+1
(Assignee)

Comment 5

2 years ago
Created attachment 8758402 [details]
MozReview Request: Bug 1276338 - chrome.runtime.id is undefined in content scripts, r?kmag

Review commit: https://reviewboard.mozilla.org/r/56634/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/56634/
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

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)
(Assignee)

Comment 7

2 years ago
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)
(Assignee)

Comment 8

2 years ago
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+
(Assignee)

Comment 10

2 years ago
https://treeherder.mozilla.org/#/jobs?repo=try&revision=7f8ac0527d59
(Assignee)

Updated

2 years ago
Keywords: checkin-needed

Comment 11

2 years ago
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

Comment 12

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/1b67bc89fe9a
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox49: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.