use XDG data directory for log files
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
"string-dedent": "^3.0.2",
|
||||
"user-agents": "^1.1.669",
|
||||
"ws": "^8.18.3",
|
||||
"xdg-basedir": "^5.1.0",
|
||||
"zod": "^3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url'
|
||||
import vm from 'node:vm'
|
||||
import dedent from 'string-dedent'
|
||||
import { createPatch } from 'diff'
|
||||
import { getCdpUrl } from './utils.js'
|
||||
import { getCdpUrl, getLogFilePath } from './utils.js'
|
||||
import { waitForPageLoad, WaitForPageLoadOptions, WaitForPageLoadResult } from './wait-for-page-load.js'
|
||||
import { getCDPSessionForPage, CDPSession } from './cdp-session.js'
|
||||
|
||||
@@ -92,7 +92,7 @@ const lastSnapshots: WeakMap<Page, string> = new WeakMap()
|
||||
const cdpSessionCache: WeakMap<Page, CDPSession> = new WeakMap()
|
||||
|
||||
const RELAY_PORT = 19988
|
||||
const LOG_FILE_PATH = process.env.PLAYWRITER_LOG_PATH || path.join(os.tmpdir(), 'playwriter-relay-server.log')
|
||||
const LOG_FILE_PATH = getLogFilePath()
|
||||
const NO_TABS_ERROR = `No browser tabs are connected. Please install and enable the Playwriter extension on at least one tab: https://chromewebstore.google.com/detail/playwriter-mcp/jfeammnjpkecdekppnclgkkffahnhfhe`
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { startPlayWriterCDPRelayServer } from './extension/cdp-relay.js'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import os from 'node:os'
|
||||
import util from 'node:util'
|
||||
import { ensureDataDir, getLogFilePath } from './utils.js'
|
||||
|
||||
const logFilePath = process.env.PLAYWRITER_LOG_PATH || path.join(os.tmpdir(), 'playwriter-relay-server.log')
|
||||
const logFilePath = getLogFilePath()
|
||||
|
||||
process.title = 'playwriter-ws-server'
|
||||
ensureDataDir()
|
||||
fs.writeFileSync(logFilePath, '')
|
||||
|
||||
const log = (...args: any[]) => {
|
||||
|
||||
@@ -1,4 +1,37 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { xdgData } from 'xdg-basedir'
|
||||
|
||||
export function getCdpUrl({ port = 19988, host = '127.0.0.1' }: { port?: number; host?: string } = {}) {
|
||||
const id = `${Math.random().toString(36).substring(2, 15)}_${Date.now()}`
|
||||
return `ws://${host}:${port}/cdp/${id}`
|
||||
}
|
||||
|
||||
export function getDataDir(): string {
|
||||
return path.join(xdgData!, 'playwriter')
|
||||
}
|
||||
|
||||
export function ensureDataDir(): string {
|
||||
const dataDir = getDataDir()
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true })
|
||||
}
|
||||
return dataDir
|
||||
}
|
||||
|
||||
export function getLogFilePath(): string {
|
||||
return process.env.PLAYWRITER_LOG_PATH || path.join(getDataDir(), 'relay-server.log')
|
||||
}
|
||||
|
||||
// export function getDidPromptReviewPath(): string {
|
||||
// return path.join(getDataDir(), 'did-prompt-review')
|
||||
// }
|
||||
|
||||
// export function hasReviewedPrompt(): boolean {
|
||||
// return fs.existsSync(getDidPromptReviewPath())
|
||||
// }
|
||||
|
||||
// export function markPromptReviewed(): void {
|
||||
// ensureDataDir()
|
||||
// fs.writeFileSync(getDidPromptReviewPath(), new Date().toISOString())
|
||||
// }
|
||||
|
||||
Generated
+9
@@ -93,6 +93,9 @@ importers:
|
||||
ws:
|
||||
specifier: ^8.18.3
|
||||
version: 8.18.3(bufferutil@4.0.9)
|
||||
xdg-basedir:
|
||||
specifier: ^5.1.0
|
||||
version: 5.1.0
|
||||
zod:
|
||||
specifier: ^3
|
||||
version: 3.25.76
|
||||
@@ -2701,6 +2704,10 @@ packages:
|
||||
utf-8-validate:
|
||||
optional: true
|
||||
|
||||
xdg-basedir@5.1.0:
|
||||
resolution: {integrity: sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
xml-name-validator@5.0.0:
|
||||
resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -5479,6 +5486,8 @@ snapshots:
|
||||
optionalDependencies:
|
||||
bufferutil: 4.0.9
|
||||
|
||||
xdg-basedir@5.1.0: {}
|
||||
|
||||
xml-name-validator@5.0.0:
|
||||
optional: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user