Merge branch 'main' of https://github.com/remorses/playwriter
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Hono } from 'hono'
|
||||
import { cors } from 'hono/cors'
|
||||
import { serve } from '@hono/node-server'
|
||||
import { getConnInfo } from '@hono/node-server/conninfo'
|
||||
import { createNodeWebSocket } from '@hono/node-ws'
|
||||
@@ -418,6 +419,22 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
||||
}
|
||||
|
||||
const app = new Hono()
|
||||
// CORS middleware for HTTP endpoints - only allows our specific extension IDs.
|
||||
// This prevents other extensions from reading responses via fetch/XHR.
|
||||
// WebSocket connections have their own separate origin validation.
|
||||
app.use('*', cors({
|
||||
origin: (origin) => {
|
||||
if (!origin.startsWith('chrome-extension://')) {
|
||||
return null
|
||||
}
|
||||
const extensionId = origin.replace('chrome-extension://', '')
|
||||
if (!OUR_EXTENSION_IDS.includes(extensionId)) {
|
||||
return null
|
||||
}
|
||||
return origin
|
||||
},
|
||||
allowMethods: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
||||
}))
|
||||
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app })
|
||||
|
||||
const getCdpWsUrl = (c: { req: { header: (name: string) => string | undefined } }) => {
|
||||
|
||||
Reference in New Issue
Block a user