From 0400f86c1587cb58ced83bd91af51ab90cc7df2d Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Mon, 27 Jan 2025 09:44:14 +0900 Subject: [PATCH] `location` is not available in Node.js environment Fixes #218 --- websocket/findMetadata.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/websocket/findMetadata.ts b/websocket/findMetadata.ts index d5cb57a..fe0b6c1 100644 --- a/websocket/findMetadata.ts +++ b/websocket/findMetadata.ts @@ -61,8 +61,10 @@ export const findMetadata = ( const fileUrlPattern = new RegExp( `${ - location?.origin ?? "https://scrapbox.io" - }/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$`, + // For Node compatibility, we need to access `location` via `globalThis` + // deno-lint-ignore no-explicit-any + (globalThis as any).location?.origin ?? + "https://scrapbox.io"}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$`, ); const lookup = (node: Node) => {