Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Puppeteer for Firefox #198

Open
m90 opened this issue Mar 13, 2019 · 6 comments
Open

Support Puppeteer for Firefox #198

m90 opened this issue Mar 13, 2019 · 6 comments

Comments

@m90
Copy link
Collaborator

m90 commented Mar 13, 2019

Puppeteer now has experimental support for Firefox which would enable Mochify to run tests in Node, Chrome and Firefox (which is pretty great).

Looking at the table of already supported APIs everything that Mochify uses should already be implemented and theoretically the modules could just be hotswapped depending on which browser is targeted.

One big question I don't know an answer for: does this mean Mochify would include both puppeteer as well as puppeteer-firefox as a dependency (which would result in an even heftier install, probably too hefty) or should puppeteer-firefox live as an optionalDependency or peerDependency, or as something completely different? (Caveat: I don't know if puppeteer-firefox is even supposed to stay a dedicated package once it is mature, although I would be surprised if it wouldn't).


NB: As of March 2019 puppeteer-firefox has a bug where pages run in the context of file:// will not trigger console events, thus preventing usage with Mochify right now.

@mantoni
Copy link
Owner

mantoni commented Mar 13, 2019

Mochify is structured relatively modular now. I’m developing towards the goal of having every feature being a thing that is added to the Browserify pipeline. Eventually projects like min-wd and consolify should be plugins that can be optionally installed. The Firefox integration could also be a plugin. I’m dreaming of creating an org for these projects.

In reality, I don’t have the time to realize this. I’m glad to assist and review if you want to help :)

@m90
Copy link
Collaborator Author

m90 commented Aug 3, 2020

So puppeteer/puppeteer#3652 got closed and it seems that it should now be possible to run tests against Firefox too (I also think ™️ I just got a test passing on my machine using Firefox following the instructions here: https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#puppeteerlaunchoptions).

The nice thing is that this can be achieved by passing a product parameter (i.e. mochify wouldn't need to introduce an extra dependency but only learn about a new option).

Parts that worry me about it though are:

  • The puppeteer version mochify is using is 4 major versions behind, will this require major changes?
  • There are lots of things in mochify that refer to chromium, should all of this be renamed if we'd add Firefox support?
  • Installing Firefox for puppeteer seems brittle right now. Is this something we'd leave up to users or try to have mochify do for them?

@m90
Copy link
Collaborator Author

m90 commented Aug 6, 2020

I looked into this a little further.

Upgrading to Puppeteer 5 seems to work with two caveats:

  • we'd have to drop Node 6 and 8
  • Puppeteer now uses the fs.promises API which means Node 10 will log a lot of warnings about its usage. Tests will need to be run with NODE_NO_WARNINGS=1 to silence this

As for running the tests in Firefox, this seems to work mostly, but sometimes Firefox will log unexpected things in addition, sometimes it times out and other times tests fail for reasons I don't understand. It also seems to be pretty slow. I'll look into it further when I find the time to do so.

@mantoni
Copy link
Owner

mantoni commented Aug 6, 2020

Thank you for investigating. I'm currently too busy with other things. It would be great to support Firefox. But if it's too brittle, it can wait, I think. I'm not too keen having issues in Mochify that arn't related to the project itself.

My thoughts on your points:

  • Dropping older node versions with a new major release is fine. They're end of life. Especially if we're upgrading puppeteer majors anyway.
  • If puppeteer doesn't run without warnings in node 10 anymore, we should probably drop support for that version too.
  • Things that refer to chromium could be renamed to puppeteer. Should we introduce an additional argument which engine to use?

@m90
Copy link
Collaborator Author

m90 commented Aug 6, 2020

But if it's too brittle, it can wait, I think.

I totally share that sentiment. I can keep an eye on how the Firefox integration in Puppeteer evolves and whenever it seems to be mature enough, we can pull it into Mochify. It'd be especially important that you can install both Chromium and Firefox side by side without jumping through too many hoops (right now it's a lot of hoops still).

Should we introduce an additional argument which engine to use?

--engine with a default of chromium sounds fab.

@m90
Copy link
Collaborator Author

m90 commented May 31, 2021

I just looked into this again and it seems the issue we are seeing with Firefox <-> Puppeteer has not been resolved yet.

Looking for alternatives I tried swapping out Puppeteer with Playwright and this seems to bring us much closer to supporting Firefox. The APIs of the two libraries are mostly identical (18d9123#diff-8aa031d8dc1e01f5f5af954cda92a1e567897406df81a442fb1a494cdb9f3648) and most tests already pass when using Firefox (albeit it's much slower than chromium). There are some Chromium specific things (e.g. --web-security flag) Mochify would need to figure out still, but probably nothing too major.

Since you've been talking about a revamped Mochify @mantoni recently I am not sure however if the effort is worth it (especially considering this will likely bring some breaking changes for consumers in some cases). I'd be happy to spend some time looking into this further in the next few weeks, but I also don't have to.

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

No branches or pull requests

2 participants