vuejs / devtools-v6

⚙️ Browser devtools extension for debugging Vue.js applications.
https://devtools-v6.vuejs.org/
MIT License
24.69k stars 4.14k forks source link

Proposal: publish `shell-chrome` sub-package to npm. #2035

Open Tanimodori opened 1 year ago

Tanimodori commented 1 year ago

What problem does this feature solve?

I suggest to publish shell-chrome sub-package as a separate package to npm like shell-electron and api to help simplify the debugging of electron applications.

Normal web apps can easily access vue devtools by simply downloading it from browser extension market, but it is not the case for electron apps.

If you want to add vue devtools to the integrated devtools of electon, as the electron docs said, you need to get the unzipped form of crx extension, which is located in VUE_DEVTOOLS_PATH, and load by session.defaultSession.loadExtension

if (import.meta.env.DEV) {
  app.whenReady().then(() => {
    session.defaultSession.loadExtension(VUE_DEVTOOLS_PATH, {
      allowFileAccess: true,
    });
  });
}

Currently the only available distribution of latest compiled shell-chrome is at Chrome/Edge store:

There are problems of downloading from such a store:

That's what the good old electron-devtools-installer does which is unmaintained 2 years ago. Download from chrome store, put into %APPDATA%/extensions and load into electron devtools. You can loaded from locally installed extension from Chrome with:

if (import.meta.env.DEV) {
  app.whenReady().then(() => {
    if (!process.env['APPDATA']) {
      throw new Error('Could not load extensions from local');
    }
    const extPath = join(
      process.env['APPDATA'],
      '../Local/Google/Chrome/User Data/Default/Extensions/nhdogjmejiglipccpnnnanhbledajbpd',
    );
    const extVersions = readdirSync(extPath);
    const VUE_DEVTOOLS_PATH = join(extPath, extVersions[0])
    session.defaultSession.loadExtension(VUE_DEVTOOLS_PATH, {
      allowFileAccess: true,
    });
  });
}

But you need to update using Chrome and still having update delays.

Publishing should be easy as to add pub:chrome command to package.json.

Currently @vue/devtools is not loadable by electron Chromium as it lacks manifest. I tried to load the artifact of building shell-chrome which works perfectly. As the package is published we can add it to devDependency and point VUE_DEVTOOLS_PATH to node_modules, which will get rid of tree-shaking problem.

Why not using @vue/devtools directly?