Skip to content
New issue

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

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

Already on GitHub? # to your account

Can't import (and not use) with webpack #100

Closed
revmischa opened this issue Apr 3, 2018 · 3 comments
Closed

Can't import (and not use) with webpack #100

revmischa opened this issue Apr 3, 2018 · 3 comments

Comments

@revmischa
Copy link

I'm writing code which I share between a web page and an extension, and I'm using webpack. So this presents a giant problem for me in that I can't import browser from 'webextension-polyfill' in shared code because it tries to do things like poke at chrome on import.
I'm trying to use dynamic imports but that's really a sub-par solution.

I'd like to be able to import webextension-polyfill without it crashing a web page on import.

I get this in Safari: https://user-images.githubusercontent.com/245131/37903693-7a0bee60-3101-11e8-99a3-e5e5d4389cea.png

@Rob--W
Copy link
Member

Rob--W commented Apr 3, 2018

The polyfill requires a chrome object in order to work as expected. What do you expect to happen when you call import browser from 'webextension-polyfill' from a web page?

@revmischa
Copy link
Author

I would expect it to not do anything on import that would throw an exception. Perhaps checking typeof(chrome) != 'undefined'. I would expect it to throw an exception if I call stuff on it later, but not during import if chrome is undefined.

@Rob--W
Copy link
Member

Rob--W commented Jul 5, 2018

Are dynamic imports feasible? Can you conditionally load the polyfill only when it is needed?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants