-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Firefox WebExtension (and themeName support) #802
Conversation
Looks good so far! |
shells/firefox/panel/run.js
Outdated
// If available, mirror the current Firefox devtools theme: | ||
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/devtools.panels/themeName | ||
if (typeof devtools !== 'undefined' && devtools.panels) { | ||
switch (devtools.panels.themeName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be browser.devtools.panels.themeName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried devtools.panels
(shown on this page), browser.devtools.panels
(shown on this page), and chrome.devtools.panels
(shown on this page) but all were undefined. Since the docs mention all of them, I took a guess with devtools.panels
since it seems to be mentioned more than the other 2 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now wondering if this is because this code is an add-on sdk environment and that API is part of the WebExtensions. browser.devtools.panels.themeName
should work if you load the Chrome WebExtension into Firefox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure what that means 😁
Edit I found this which, coupled with your comment above, makes me think that I should be using a WebExtensions SDK instead of the add-ons SDK. I'm not sure how that works but I'll read up. (I'm still pretty new to extensions.)
Edit 2 I also found this related issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! I think I've figured it out. Seems like I need to mimic the structure in shells/chrome for firefox, and then run web-ext run --firefox=/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin
from the directory. This is a bit more complicated a change than I anticipated. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked away and you went all the way down the 🐰 hole! 😲
5dec92e
to
b64fd01
Compare
Hey @clarkbw 😁 I just noticed that this PR has shifted in such a way as to overlap with #524 Seems like there's some issue for non-nightly builds (mentioned in the description) but otherwise it seems like the Chrome shell works fine in Firefox. Maybe we could combine forces and finish this effort? Probably worth renaming |
const themeName = (chrome.devtools.panels : any).themeName === 'dark' | ||
? 'ChromeDark' | ||
: 'ChromeDefault'; | ||
const IS_CHROME = navigator.userAgent.indexOf('Firefox') < 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this too clunky? Should I try to inject this parameter via the build script (or similar)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same thing we did for the redux extension zalmoxisus/redux-devtools-extension@0cf6830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice! 😁
💯
Agreed |
Ah, nevermind. I think it's b'c we have a reference to |
bug 1300590 only just landed in Firefox 55 and is required for features related to inspecting and console. And bug 1300587 landed in 54 which allows for creating the panel. We might need to set the min version at Fx 55 |
Hm. Yeah. That seems reasonable I guess. We have too many references we'd have to guard against otherwise. |
If it's I have been seeing errors within the |
|
Oh right! Fx 54 starts rolling out next week. |
We'll need to figure out a way to use a separate manifest file for the Firefox version so we can set the min Fx version needed. "applications": {
"gecko": {
"strict_min_version": "55"
}
} More details here and here. However, like you pointed out, that could be done with something like #632 I'd imagine the build steps are something like this:
|
I was thinking it might make sense to restructure things:
Then use a build script (similar to the approach in #632) to package each of the extensions using their own manifests but the shared source. The resulting output could also be stored in the browser-specific directory (eg This way |
Now Firefox and Chrome can both share the same source and build script while exporting separate Firefox and Chrome targets.
4873dcd
to
34d8625
Compare
I'm going to restructure the code slightly to enable parallel builds by using a temp dir for each build. This will also avoid possibly cluttering the workspace with copied manifests if the build script dies in the middle. Should be easy to do though. |
+1 on the use of |
"applications": { | ||
"gecko": { | ||
"id": "extension@react.devtools", | ||
"strict_min_version": "54.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should check the versions here. Things mostly work in 54 and definitely work in 55
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Belated follow-up...) My own testing seemed to suggest that everything except the theme worked in 54, and that degrades gracefully to the light theme.
shells/firefox/manifest.json
Outdated
{ | ||
"manifest_version": 2, | ||
"name": "React Developer Tools", | ||
"description": "Adds React debugging tools to the Chrome Developer Tools.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Chrome/Firefox/ 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops 😅
Also supports building Firefox and Chrome in parallel.
Okay. The new build script feels pretty solid now. Based on my testing, it generates a useable extension for Chrome (58) and Firefox (54 and 55). |
shells/firefox/build.js
Outdated
console.log('web-ext run --firefox=nightly'); | ||
console.log('web-ext run --firefox=/Applications/Firefox54.app/Contents/MacOS/firefox-bin'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps in the Fx README if we link to the Firefox releases and people download those then they can use --firefox=firefox
or --firefox=beta
or --firefox=nightly
and it should just work. I think Firefox54.app
might be a custom location.
Right now Firefox is 53, Beta is 54, Nightly is 55. Of course next week those numbers will all bump up by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon Any thoughts on this one? 😄 |
Firefox 54 is rolling out today. Going to test this extension in a fresh install once the final release is available and then I'd like to merge this branch. 😄 |
I chatted a bit more with Bryan and it sounds like- after we merge this PR, if we decide to release an update for Firefox versions <=54, we could always release the old version, tag it with |
FYI I'm doing another round of testing this morning for this branch. Assuming I don't find any problems, I'm merging it. |
Resolves #705 and #524
Note that this change will mean dropping support for Firefox <= 53 with future releases of the extension. I think this is the right decision to make going forward. Firefox 54 has been released.
Firefox 54 is targeted for release on 2017-06-13. I think it's worth reviewing this diff now, but maybe we should hold off on merging it until the 13th.tl;dr
shells/webextension
directorynpm run build:extension
Firefox themeName (#705)
The default Firefox theme will work as before for Firefox 54 (and earlier). As of the upcoming Firefox 55, DevTools will mimic Firefox's active theme. (This can currently be tested against the Firefox Nightly release.)
References
Change to WebExtensions (#524)
Firefox recently added a new API for
browser.devtools.panels.themeName
. After some testing it became apparent that this API is only available for WebExtensions and not add-ons (see here). Since Firefox will be dropping add-on support in the future anyway (by the end of the year) it seems the way forward is to switch over to using the WebExtensions build for Firefox as well.To do this, we could fork the Chrome extension. However there's no differences other than the injected theme name that I'm aware of, so I don't think that's necessary (cc @clarkbw for confirmation). Instead I opted for updating the Firefox shell instructions to reference the Chrome shell instead. (WebExtensions support was first previewed in Firefox 42, in 2015, so hopefully this won't cause any backwards compatibility issues either?)
Another nice thing about switching over Firefox to use the WebExtension is that the DevTools dev-mode icon will work:
Here's the output of the new build script. (Isn't it pretty? 😅)