44370833f7
The extension now reports which playwriter version it was built with via a `?v=` query param on its WebSocket connection to the relay. The relay stores this and exposes it in `/extension/status` and `/extensions/status` endpoints. CLI and MCP compare the extension's bundled version against their own VERSION. If the extension was built with a newer playwriter, a warning is shown: Playwriter 0.0.60 is outdated (extension requires 0.0.62). Run `npm install -g playwriter@latest` or update the playwriter package. This is fully backward compatible: - Old extensions without `?v=` get `playwriterVersion: null`, no warning - No WS protocol changes (version is in URL query params) - Warning fires once per executor/session lifetime Flow: vite build reads playwriter/package.json → injects __PLAYWRITER_VERSION__ → extension sends ?v=X.Y.Z on WS connect → relay stores in ExtensionInfo → /extension/status returns playwriterVersion → CLI/executor checks & warns
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { fileURLToPath } from 'node:url';
|
|
import { readFileSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { defineConfig } from 'vite';
|
|
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
// Bundle the playwriter package version into the extension so it can report
|
|
// which playwriter version it was built against. CLI/MCP use this to warn
|
|
// when the extension is outdated.
|
|
const playwriterPkg = JSON.parse(
|
|
readFileSync(resolve(__dirname, '../playwriter/package.json'), 'utf-8')
|
|
);
|
|
|
|
const defineEnv: Record<string, string> = {
|
|
'process.env.PLAYWRITER_PORT': JSON.stringify(process.env.PLAYWRITER_PORT || '19988'),
|
|
'__PLAYWRITER_VERSION__': JSON.stringify(playwriterPkg.version),
|
|
};
|
|
if (process.env.TESTING) {
|
|
defineEnv['import.meta.env.TESTING'] = 'true';
|
|
}
|
|
|
|
// Allow tests to build per-port extension outputs to avoid parallel run conflicts.
|
|
const outDir = process.env.PLAYWRITER_EXTENSION_DIST || 'dist';
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
viteStaticCopy({
|
|
targets: [
|
|
{
|
|
src: resolve(__dirname, 'icons/*'),
|
|
dest: 'icons'
|
|
},
|
|
|
|
{
|
|
src: resolve(__dirname, 'manifest.json'),
|
|
dest: '.',
|
|
transform: (content) => {
|
|
const manifest = JSON.parse(content);
|
|
|
|
// Only include tabs permission during testing
|
|
if (process.env.TESTING) {
|
|
if (!manifest.permissions.includes('tabs')) {
|
|
manifest.permissions.push('tabs');
|
|
}
|
|
}
|
|
|
|
// Inject key for stable extension ID in dev/test builds (not production)
|
|
// This ensures all developers get the same extension ID: pebbngnfojnignonigcnkdilknapkgid
|
|
if (!process.env.PRODUCTION) {
|
|
manifest.key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCJoq5UYhOo5x8s50pVBUHjQ8idyUHnZFDj1JspWJPe6kvM7RFIaE/y5WTAH05kuK0R7v/ipcGA4ywA5wKdPKHZzkl5xstlNPj0Ivu4CqLobU7eY5G3k3Gq7wql2pbwb/A8Nat4VLbfBjQLA6TGWd3LQOHS6M0B3AvrtEw7DLDUdGKh4SCLewCbdlDIzpXQwKOzrRPyLFBwj9eEeITy5aNwJ9r9JMNBvACVZiRCHsGI6DufU+OiIO232l/8OoNNt6kdTMyNgiqOogFApXPJwREUwZHGqjXD3s6bXiBIQtwkNyZfemHKkxj6g/fhCV2EMgTY6+ikQEY1gEJMrRVmcYQIDAQAB';
|
|
}
|
|
|
|
return JSON.stringify(manifest, null, 2);
|
|
}
|
|
},
|
|
]
|
|
})
|
|
],
|
|
|
|
build: {
|
|
outDir,
|
|
emptyOutDir: false,
|
|
minify: false,
|
|
rollupOptions: {
|
|
input: {
|
|
background: resolve(__dirname, 'src/background.ts'),
|
|
offscreen: resolve(__dirname, 'src/offscreen.html'),
|
|
welcome: resolve(__dirname, 'src/welcome.html'),
|
|
},
|
|
output: {
|
|
entryFileNames: '[name].js',
|
|
format: 'es',
|
|
},
|
|
},
|
|
},
|
|
define: defineEnv
|
|
});
|