Skip to content

Commit

Permalink
Support globals and client lib injection
Browse files Browse the repository at this point in the history
  • Loading branch information
shalithasuranga committed Oct 30, 2024
1 parent 300c407 commit 17fe35e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface Window {
NL_PATH: string;
/** Returns true if extensions are enabled */
NL_EXTENABLED: boolean;
/** Returns true if the client library is injected */
NL_GINJECTED: boolean;
/** Returns true if globals are injected */
NL_CINJECTED: boolean;
/** Operating system name: Linux, Windows, Darwin, FreeBSD, or Uknown */
NL_OS: OperatingSystem;
/** CPU architecture: x64, arm, itanium, ia32, or unknown */
Expand Down
4 changes: 3 additions & 1 deletion src/types/api/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface WindowOptions extends WindowSizeOptions, WindowPosOptions {
useSavedState?: boolean;
exitProcessOnClose?: boolean;
extendUserAgentWith?: string;
injectGlobals?: boolean;
injectClientLibrary?: boolean;
processArgs?: string;
}

Expand All @@ -27,4 +29,4 @@ export interface WindowOptions extends WindowSizeOptions, WindowPosOptions {
export interface WindowPosOptions {
x: number;
y: number;
}
}
4 changes: 3 additions & 1 deletion src/ws/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const extensionMessageQueue = {}
export function init() {
initAuth();
const connectToken: string = getAuthToken().split('.')[1];
ws = new WebSocket(`ws://${window.location.hostname}:${window.NL_PORT}?connectToken=${connectToken}`);
const hostname: string = (window.NL_GINJECTED || window.NL_CINJECTED) ?
'localhost' : window.location.hostname;
ws = new WebSocket(`ws://${hostname}:${window.NL_PORT}?connectToken=${connectToken}`);
registerLibraryEvents();
registerSocketEvents();
}
Expand Down

0 comments on commit 17fe35e

Please sign in to comment.