GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

Possible to use in Chrome extension? #19

Closed GreenFootballs closed 3 years ago

GreenFootballs commented 3 years ago

Hi, this is a great little library, but since it uses import to do its thing, it's difficult if not impossible to use in a Chrome extension (which I'm currently developing), because there's no way to set the file type to 'module' in the extension manifest. This needs to run in the content script, and injecting a script tag into the DOM has some big limitations.

Is there any way to use the current code in an extension, or could parts of it be extracted to work as simple functions in a standard JS file?

tomayac commented 3 years ago

It should be possible to use modules in extensions. This article outlines the general steps for all components. Note the update that references this post for content scripts. I'm closing this issue for now, but feel free to comment further and I am happy to provide help if need be.

tomayac commented 3 years ago

Oh, and at the risk of pointing out the obvious: you can of course just use a bundler like rollup.js.

GreenFootballs commented 3 years ago

Thanks, I got it to work! I was having lots of trouble trying to use dynamic import with the code as is, but rollup.js was the magic I needed. This is the command line I used to generate the bundle:

rollup ./src/index.js --file ./bundle/nativefs.js --inlineDynamicImports

tomayac commented 3 years ago

Thanks for reporting back on your success! Happy you got this working for you!