I have been trying to get a Next.js browser extension to work using the app router. Unfortunately, I have been hitting the following error when I open the extension after I loaded it into [ARC/BRAVE/CHROME]:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-o+vI5waJFQ8KpujZ+vH6gMOPl05v7BWUyGDbDio2hSg=')" or a nonce ('nonce-...') is required to enable inline execution.
It’s a pretty simple npx create-next-app@latest
template, primarily using the app router, which seems to return an error when built and loaded as an extension. The only changes I made are:
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
distDir: "out",
output: "export",
};
export default nextConfig;
// package.json
...
"scripts": {
"dev": "next dev",
"build": "next build && mv out/_next out/next",
"start": "next start",
"lint": "next lint"
},
...
// public/manifest.json
{
"name": "demo",
"version": "1.0.0",
"manifest_version": 3,
"action": {
"default_popup": "index.html"
}
}
What I have tried:
- Added
INLINE_RUNTIME_CHUNK=false
to a.env
file (reference). - Added
"content_security_policy": { "extension_pages": "script-src 'self' 'unsafe-inline', scripts.js" }
to the
manifest.json
. - Checked and replaced references to
/_next
in theindex.html
usingsed -i 's/_next/next/g' "./out/index.html"
- Added
'use client'
to thepage.tsx
. - Used the page router instead, which worked, but I want to use the app router.