How do I get access to all the files in the extension in Chrome Extension Manifest Version 3 (MV3)?
Asked Answered
S

1

12

Background

I've been using the crx-hotreload package to auto-reload my chrome extensions during development because it's annoying to have to click the refresh button on the Extensions page every time you make a change; however, this package doesn't work with MV3 because it uses the chrome.runtime.getPackageDirectoryEntry method, which seems to have been removed from chrome.runtime in MV3. I can't find documentation to confirm that it was removed, but it's not there when I try to use it.

Questions

Does anyone know how to get access to all the files in the extension directory in Chrome Extension Manifest Version 3?

Or generally, is there a better way that I can hot-reload my chrome extensions during development that would work for MV3?

Superaltar answered 31/1, 2021 at 4:11 Comment(0)
Q
12

This is one of many things based on DOM capabilities of background pages that are removed from ManifestV3 because service workers don't have DOM. For example, getPackageDirectoryEntry is using the old nonstandard FileSystem API in its returned value.

As to why, apparently the switch to service workers simplifies the internal source code in Chromium, even if it doesn't provide any real improvements for extension authors or users.

At this point all you can do is present a convincing use case and ask Chromium developers via https://crbug.com to implement an alternative API.

Quake answered 31/1, 2021 at 6:26 Comment(4)
Thank you for the links to Chromium. Do you know of any other hot-reload methods I could try for extension development?Superaltar
Either don't use ManifestV3 or add a separate html file that you can open in a separate window so its js files will be able to use the classic methods including getPackageDirectoryEntry.Quake
Does it mean there is no way to read the webext files from within service worker in MV3?Simferopol
Nope... Nothing's changed since the answer was published. Note that you can read the files if the name is known, you just can't get the list of files/directories, but that shouldn't be a problem if you use a build system - you can add a build step to generate the list.Quake

© 2022 - 2024 — McMap. All rights reserved.