-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra HTML pages don't find the src file in dev #627
Comments
It would help to understand how you're including this html file in your manifest.json, is it under If it is, I've found I needed to fully qualify the file location, so instead of |
@corrortiz Please include at least the manifest and the source HTML file. |
Having the same issue with defining the html page on web_accessible_resources "web_accessible_resources": [
{
"resources": ["src/pages/sidebar/index.html"],
"matches": ["http://*/*", "https://*/*"]
}
] in <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sidebar</title>
</head>
<body>
<div id="__root"></div>
<script type="module" src="./index.tsx"></script>
</body>
</html> in import { createRoot } from "react-dom/client";
import Sidebar from "./components/Sidebar";
function init() {
const rootContainer = document.querySelector("#__root");
if (!rootContainer) throw new Error("Can't find Panel root element");
const root = createRoot(rootContainer);
root.render(<Sidebar />);
}
init(); It just copies the html as it is, without processing the tsx file linked to it to dist - |
Also, There seems to be an issue with loading the page into an iframe in content. It is functioning correctly on build, however, during development, the page fails to load in the iframe. Interestingly, the page is able to load normally when opened in a new tab. |
@Royal-lobster, ideally relative imports work, but have you tried referencing the js file relative to the build location (rather than relative to the html file)? |
It's not building the js bundle for that page. unless defining it on roll-up build settings in vite config. Defining it on the roll-up option input works as expected. (With relative to html file as well) |
@Royal-lobster Did you find any workarounds for this issue? |
For HTML Page, i just added roll up build setting in vite config https://github.com/Royal-lobster/Syncia/blob/main/vite.config.ts But for iframe not rendering within content script on dev, its painful. i am developing the iframe page isolated in chrome-extension:// link if i were to test on page, i should build every time for every change i make. i think i should make a new issue for it |
@Royal-lobster in dev you can simply load the http://localhost:5173 url instead of the extension page as a workaround. |
IFrame loading (extension html page) in content script can be fixed by adding port config in Here's the vite config:
|
I'm having the same issue when creating panes & panels: manifest: {
// …
devtools_page: 'main.html',
} main.html: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script src="main.js" type="module"></script>
</body>
</html> main.js chrome.devtools.panels.create('my devtool', '', '/panel.html');
chrome.devtools.panels.elements.createSidebarPane('my devtool', (sidebar) =>
sidebar.setPage('/pane.html'),
); |
I'm facing same issue, trying to create a |
Wow thanks a lot ! You made my life easy |
I have the same issue with "offscreen.html". Should I close / remove it? I still can't make workaround work... |
@SeekerOfTrueCode have you found a solution? Currently, I'm trying to figure out how to use Chrome offscreen API with this tool (crxjs/chrome-extension-tools), but I have issues. What I have: // vite.config.ts
const PORT = 5173
export default defineConfig({
// Other stuff
plugins: [
react(),
crx({ manifest }),
],
build: {
outDir: 'dist',
rollupOptions: {
input: {
offscreen: resolve(process.cwd(), 'src/app/offscreen.html'), // According to https://crxjs.dev/vite-plugin/concepts/pages#extra-html-pages
},
},
},
server: {
strictPort: true,
port: PORT,
hmr: {
clientPort: PORT,
},
},
} // manifest.ts
export default defineManifest({
// Other stuff
manifest_version: 3,
permissions: ['offscreen'],
host_permissions: ['<all_urls>'],
background: {
service_worker: 'src/app/background.ts',
type: 'module',
},
web_accessible_resources: [
{
resources: ['src/app/offscreen.html'], // According to https://github.com/crxjs/chrome-extension-tools/issues/767#issuecomment-1809560172
matches: ['<all_urls>'],
},
],
}, // src/app/offscreen.html
<script type="module" src="/src/app/offscreen.ts"></script> // src/app/background.ts
await chrome.offscreen.createDocument({
url: chrome.runtime.getURL('src/app/offscreen.html'),
reasons: ['DOM_PARSER'],
justification: 'Process Images',
}); ...but I'm getting the error |
@supfiger What worked for me was to bring down the manifest.json {
...
"permissions": ["activeTab", "offscreen", "tabCapture"],
"background": {
"service_worker": "src/background.ts",
"type": "module"
},
"web_accessible_resources": [{
"resources": ["offscreen.html", "offscreen.js"],
"matches": ["<all_urls>"]
}]
} vite.config.ts import path from "path"
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { crx } from '@crxjs/vite-plugin'
import manifest from './manifest.json'
export default defineConfig({
plugins: [
react(),
crx({ manifest }),
],
build: {
rollupOptions: {
input: {
offscreen: 'offscreen.html',
},
}
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}) |
To properly use additional HTML pages with scripts in Chrome extensions during development and production with CRXJS, follow these guidelines: 1.
|
The last comment worked for me in parts (thanks geanrt), even though it included the page and the script to the development build it didn't compile the ts file. |
Thanks for contributing to CRXJS! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days. |
Build tool
Vite
Where do you see the problem?
Describe the bug
When you run the dev server the the extra HTML don't generate the reference to the source file, when you run the build command you get the correct reference:
Output with the vite build command (this works correctly):
Output with the vite build command:
I try to add the file with
rollup-plugin-copy
but its not working as it does not generate the missing fileReproduction
N/A
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: