wxt-dev / wxt

⚡ Next-gen Web Extension Framework
https://wxt.dev
MIT License
4.32k stars 180 forks source link

[vite-plugin-obfuscator] Obfusticator plugin does not work #486

Closed xbears closed 7 months ago

xbears commented 7 months ago

Describe the bug

Enabling the vite obfuscator plugin in wxt causes the content script to not work.

I found that the vite plugin in wxt with apply:'build' configured was still being run with pnpm dev, There are no issues with this vite plugin and works just fine in normal vite projects.

To Reproduce

wxt-test.zip

  1. Install dependencies: pnpm i
  2. Start dev mode: pnpm dev

Screenshots

https://github.com/wxt-dev/wxt/assets/650444/a92cbcf3-fbc8-4ec2-bced-760de4211690

Environment

  System:
    OS: Windows 11 10.0.23601
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 17.65 GB / 31.93 GB
  Binaries:
    Node: 20.6.1 - C:\soft\nodejs\node.EXE
    npm: 9.8.1 - C:\soft\nodejs\npm.CMD
    pnpm: 8.12.0 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (120.0.2210.61)
    Internet Explorer: 11.0.23601.1000
aklinker1 commented 7 months ago

It's being applied because content scripts are built using library mode during development. If you only want to apply it during the dev command, you'll have to manually choose when it's applied. Something like this should work fine:

vite: ({ command }) => ({
  plugins: [
    command === "dev" ? Obfusticator() : [],
  ],
}),

But if it doesn't work in development, I doubt it will work in production...

aklinker1 commented 7 months ago
Screenshot 2024-02-24 at 12 19 46 PM

The CLI is reporting some kind of error, but I can't figure out what they are since the obfuscation plugin doesn't support source maps, and the error message is swallowed. I also can't log anything in the service worker when running the dev command, and none of the logs I'd expect to see are printed. I imagine the obfustication plugin is also responsible for that somehow, but I didn't look into it too much.

Can confirm, the production build of the extension doesn't work either. So I don't know what's going on... I would just recommend not using the plugin and relying on the default minification settings for now. I won't have time to debug this any further today, and the plugin doesn't make it easy. So yeah, this will probably be in limbo for a while.

xbears commented 7 months ago

Thank you very much for your reply, I tried switching to the rollup plugin rollup-plugin-obfuscator and it seems to work fine.

https://www.npmjs.com/package/rollup-plugin-obfuscator

import Obfusticator from 'rollup-plugin-obfuscator'

vite: ({ command }) => ({
  plugins: [
    command === "serve" ? [] :  Obfusticator(),
  ],
}),
aklinker1 commented 7 months ago

Ok, glad you found one that works!