Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Firefox WebExtension (and themeName support) #802

Merged
merged 15 commits into from
Jun 20, 2017
Merged

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jun 6, 2017

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

  • Delete old Firefox add-ons directory
  • Move Chrome extension to new shells/webextension directory
  • Replace old build script with new Node script
    • Can generate both Firefox and Chrome web extensions
    • Runs via npm run build:extension
  • Add support for Firefox theme mirroring

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.)

Firefox theme switching

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:

screen shot 2017-06-07 at 9 13 33 am
screen shot 2017-06-07 at 9 13 40 am

Here's the output of the new build script. (Isn't it pretty? 😅)
build-updated-3

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

Looks good so far!

// 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

@bvaughn bvaughn Jun 7, 2017

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 😅

Copy link
Contributor

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.

Copy link
Contributor Author

@bvaughn bvaughn Jun 7, 2017

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.

Copy link
Contributor Author

@bvaughn bvaughn Jun 7, 2017

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. 😁

Copy link
Contributor

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! 😲

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

Score! Running the Chrome extension in Firefox, but switching on FF's theme names:

firefox-theme

@bvaughn bvaughn changed the title Firefox themeName [WIP] Firefox WebExtension [WIP] Jun 7, 2017
@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

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 shells/chrome to something else at some point. But that could be done in a follow-up to avoid adding noise to this.

const themeName = (chrome.devtools.panels : any).themeName === 'dark'
? 'ChromeDark'
: 'ChromeDefault';
const IS_CHROME = navigator.userAgent.indexOf('Firefox') < 0;
Copy link
Contributor Author

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)?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice! 😁

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

Maybe we could combine forces and finish this effort?

💯

Probably worth renaming shells/chrome to something else at some point. But that could be done in a follow-up to avoid adding noise to this.

Agreed

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

Don't suppose you have any insight into what's going on in FF <= 53?

screen-shot-2017-06-07-at-11 02 54-am

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

Ah, nevermind. I think it's b'c we have a reference to chrome.devtools.network elsewhere that isn't being guarded against.

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

Testing in Chrome and Firefox Nightly, this seems to work great. Older versions of Firefox I have locally (47, 53) don't quite work though so I still need to look into that

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

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

Hm. Yeah. That seems reasonable I guess. We have too many references we'd have to guard against otherwise.

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

Ah, nevermind. I think it's b'c we have a reference to chrome.devtools.network elsewhere that isn't being guarded against.

If it's chrome.devtools.network.onNavigated that should also be working in Firefox. I haven't tested it directly but according to the docs it is there and I haven't seen errors previously.

I have been seeing errors within the doublePipe function which I suspect is causing problems. It appears that one of the pipe references is being lost and I'm not sure why yet.

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

Ah, nevermind. I think it's b'c we have a reference to chrome.devtools.network elsewhere that isn't being guarded against.

If it's chrome.devtools.network.onNavigated that should also be working in Firefox. I haven't tested it directly but according to the docs it is there and I haven't seen errors previously.

chrome.devtools.network is undefined for FF 53. The docs show it as being added in 54. (I only have 47, 53, and Nightly local to test with.)

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

The docs show it as being added in 54.

Oh right! Fx 54 starts rolling out next week.

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

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:

  • Build Chrome extension using the default build directory and zip it up as chrome.zip
  • Build Firefox extension with the applicationattribute injected into the manifest and zip it up as firefox.zip

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

I was thinking it might make sense to restructure things:

.
└───┬ shells/
    ├───┬ chrome/
    │   ├─── build/
    │   ├─── manifest.json
    │   └─── README.md
    ├───┬ firefox/
    │   ├─── build/
    │   ├─── manifest.json
    │   └─── README.md
    └───┬ webextension/
        ├─── helpers/
        ├─── icons/
        ├─── popups/
        ├─── src/
        ├─── main.html
        ├─── panel.html
        ├─── README.md
        ├─── webpack.backend.js
        └─── webpack.config.js

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 shells/firefox/build) to avoid confusion.

This way applicatinos.gecko.strict_min_version doesn't leak into the Chrome extension and minimum_chrome_version doesn't leak into Firefox.

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

I've got the new folder structure and process I described mostly working. (The one limitation is that you can't build both extensions at the same time. I could fix that though if we think it's important to support?)

Building Chrome

screen shot 2017-06-07 at 3 16 38 pm

Building Firefox

screen shot 2017-06-07 at 3 17 05 pm

Running the build script

building-devtools

Now Firefox and Chrome can both share the same source and build script while exporting separate Firefox and Chrome targets.
@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 7, 2017

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.

@clarkbw
Copy link
Contributor

clarkbw commented Jun 7, 2017

+1 on the use of chaulk 😄

"applications": {
"gecko": {
"id": "extension@react.devtools",
"strict_min_version": "54.0"
Copy link
Contributor

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

Copy link
Contributor Author

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.

{
"manifest_version": 2,
"name": "React Developer Tools",
"description": "Adds React debugging tools to the Chrome Developer Tools.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Chrome/Firefox/ 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops 😅

Brian Vaughn added 2 commits June 7, 2017 20:05
Also supports building Firefox and Chrome in  parallel.
@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 8, 2017

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).

@bvaughn bvaughn changed the title Firefox WebExtension [WIP] Firefox WebExtension (and themeName support) Jun 8, 2017
@bvaughn bvaughn requested a review from gaearon June 8, 2017 03:28
console.log('web-ext run --firefox=nightly');
console.log('web-ext run --firefox=/Applications/Firefox54.app/Contents/MacOS/firefox-bin');
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the README as well as the on-screen instructions.

screen shot 2017-06-08 at 8 35 01 am

@bvaughn bvaughn mentioned this pull request Jun 8, 2017
9 tasks
@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 9, 2017

@gaearon Any thoughts on this one? 😄

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 13, 2017

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. 😄

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 16, 2017

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 "strict_max_version": "53", and the add-ons store would should the right version to the user based on their browser. (To be fair, we probably want to avoid doing this because it sounds like a hassle- but at least it's an option.)

@bvaughn
Copy link
Contributor Author

bvaughn commented Jun 20, 2017

FYI I'm doing another round of testing this morning for this branch. Assuming I don't find any problems, I'm merging it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants