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())
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user