gluon/gluon.d.ts
Drake c4c0436634
update Deno branch to 0.10.0 (#31)
* cdp: add internal close api

* inject: add Window.close() api

* typedef: add Window.close()

* roadmap: add close api for 0.8.0

* release: 0.8.0

* readme: update project age

* paths: add more linux browsers

* readme: update screenshot

* readme: move trying gluon to earlier up

* inject: add useSessionId to Window.cdp.send()

* typedef: add useSessionId to CDPApi.send()

* idle: rewrite to use CDP to get processes instead of exec

* index: remove now unneeded parameters for idle creation

* chore: bump version to 0.9.0-alpha.0

* inject: pass IPC browser engine

* api: add Window.versions

* typedef: add future BrowserEngine and update Browser values

* typedef: add Window.versions

* index: rename internal variable

* idle: v2 - added sleep, utils, documenting, and more

* typedef: update for IdleApi v2

* roadmap: update

* chore: bump version to 0.9.0-alpha.2

* readme: add more feature specific statuses

* readme: make specific feature statuses into a table

* cdp: return protocol errors

* idle: move to new api dir

* controls: new Window.controls API

* darwin: full support (#4)

* meta: add pnpm-lock.yaml to .gitignore for my own sanity

* darwin: preliminary support

* chore: disable menubar key in firefox

* Add support new browsers Mac OS (#20)

Co-authored-by: a.artamonov <a.artamonov@sftpro.ru>

* roadmap: tweak

* roadmap: update done

* roadmap: remove overall

* typedef: change some voids to Promise<void>s

* typedef: add Window.controls

* release: 0.9.0

* add .vscode to gitignore

* assets: new logo

* readme: tweak features

* readme: fancy header

* readme: tweak description

* paths>win: add alternate appdata paths

* paths: add new browsers, refactor windows to auto append env

* readme: update npm link

* readme: fix license badge link

* paths: add brave

* chore: bump version to 0.10.0-alpha.2

* index: redo browser finding logging

* index: rewrite data path gen (#6)

* Added `.DS_Store` in .gitignore (#28)

* `.DS_Store` Removed

* Update .gitignore

* roadmap: update

* roadmap: add intended release date for 0.10

* launcher/inject: get browser info first, and always await

* roadmap: update

* cdp: make logging available via optional cli flag

* chore: bump version to 0.10.0-alpha.3

* chore: update alpha version in package

* inject: make eval return just result

* inject: add window.loaded promise

* ipc: add expose APIs

* roadmap: update

* gitignore: ignore gluon_data

* inject: rename Window.window -> Window.page

* typedef: rename Window.window -> page

* typedef: add PageApi.loaded

* typedef: add new IPC expose APIs

* idle: minor cleanup

* fix: hopefully remove all references to nodejs `process`

* idle: add close handler (also move API creation into inject)

* chore: bump version to alpha.5

* launcher: run Window.close on process close too

* fix: firefox was still refering to node's `process`

* gluworld: update to newest version from examples repo, fully convert to Deno

* typedefs: fix errors that deno lsp was complaining about

* release: v0.10.0

* deno: re-export src/index.ts in mod.ts to fit typical deno usage

Co-authored-by: CanadaHonk <oj@oojmed.com>
Co-authored-by: Beef <beefers@riseup.net>
Co-authored-by: Alexander Artamonov <47431914+artamonovtech@users.noreply.github.com>
Co-authored-by: a.artamonov <a.artamonov@sftpro.ru>
Co-authored-by: Mantresh Khurana <120998049+mantreshkhurana@users.noreply.github.com>
2023-01-12 16:37:37 +00:00

217 lines
4.9 KiB
TypeScript

type PageApi = {
/**
* Evaluate a string or function in the web context.
* @returns Return value of expression given.
*/
eval: (
/** String or function to evaluate. */
expression: string|Function
) => Promise<any>,
/** Promise for waiting until the page has loaded. */
loaded: Promise<void>
};
type IPCApi = {
/**
* Send an IPC event to the web context.
* @returns Replied event data (null by default).
*/
send(
/** Type of event to send. */
type: string,
/** Data of event to send. */
data: any
): Promise<any>,
/**
* Subscribe to IPC events of a specific type with a callback.
*/
on(
/** Type of event to handle. */
type: string,
/**
* Ran whenever an IPC event of type specified is received. Should return optionally with what to reply with.
* @returns Optionally with what to reply with, otherwise null by default.
*/
callback: (data: any) => any
): void,
/**
* Expose a Node function to the web context, acts as a wrapper around IPC events.
* Can be ran in window with Gluon.ipc[key](...args)
*/
expose(
/** Key name to expose to. */
key: string,
/** Handler function which is called from the web context. */
handler: Function
): void,
/**
* Unexpose (remove) a Node function previously exposed using expose().
*/
unexpose(
/** Key name to unexpose (remove). */
key: string
): void
};
type CDPApi = {
/**
* Send a CDP command to the browser.
* {@link https://chromedevtools.github.io/devtools-protocol/ Chrome DevTools Protocol Documentation}
* @returns Result of command from browser.
*/
send(
/** Method of CDP command. */
method: string,
/** Parameters of CDP command. */
params?: Object,
/** Send session ID with the command (default true). */
useSessionId?: Boolean
): Promise<any>
};
type IdleAutoOptions = {
/**
* How long the window should be minimized before hibernating, in seconds.
* @default 5
*/
timeMinimizedToHibernate?: Number
};
type IdleApi = {
/** Put the window into hibernation. */
hibernate(): Promise<void>,
/**
* Put the window to sleep.
*/
sleep(): Promise<void>,
/** Wake up the window from hibernation or sleep. */
wake(): Promise<void>,
/** Enable/disable automatic idle management, and set its options. */
auto(
/** Whether to use automatic idle management. */
enabled: Boolean,
/** Set options for automatic behavior. */
options?: IdleAutoOptions
): void
};
type VersionInfo = {
/** Name of component. */
name: string,
/** Full version of component. */
version: string,
/** Major version of component as a number. */
major: number
};
type BrowserVersions = {
/**
* Product (browser) version and name.
* @example
* Window.versions.product // { name: 'Chrome Canary', version: '111.0.5513.0', major: 111 }
*/
product: VersionInfo,
/**
* Browser engine (Chromium/Firefox) version and name.
* @example
* Window.versions.engine // { name: 'chromium', version: '111.0.5513.0', major: 111 }
*/
engine: VersionInfo,
/**
* JS engine (V8/SpiderMonkey) version and name.
* @example
* Window.versions.jsEngine // { name: 'v8', version: '11.1.86', major: 11 }
*/
jsEngine: VersionInfo
};
type ControlsApi = {
/** Minimize the browser window. */
minimize(): Promise<void>,
/**
* Maximize the browser window.
* Doesn't make the window appear (use show() before as well).
*/
maximize(): Promise<void>,
/** Show (unminimize) the browser window. */
show(): Promise<void>
}
type Window = {
/** API for the page of the window. */
page: PageApi,
/** API for IPC. */
ipc: IPCApi,
/** API for manually using CDP with the browser. */
cdp: CDPApi,
/**
* API for Gluon idle management (like hibernation).
* @experimental
*/
idle: IdleApi,
/** Browser version info of the window: product (browser), engine (Chromium/Firefox), and JS engine (V8/SpiderMonkey). */
versions: BrowserVersions,
/** Control (minimize, maximize, etc) the browser window. */
controls: ControlsApi,
/** Close the Gluon window. */
close(): void
};
/** A browser that Gluon supports. */
type Browser =
'chrome'|'chrome_beta'|'chrome_dev'|'chrome_canary'|
'chromium'|'chromium_snapshot'|
'edge'|'edge_beta'|'edge_dev'|'edge_canary'|
'firefox'|'firefox_nightly'|
'thorium'|
'librewolf';
/** A browser engine that Gluon supports. */
type BrowserEngine = 'chromium'|'firefox';
/** Additional options for opening */
type OpenOptions = {
/** Function to evaluate in the web context once loaded. */
onLoad?: Function,
/** Force Gluon to use a browser instead of automatically finding. */
forceBrowser?: Browser,
};
/**
* Open a new Gluon window.
*/
export function open(
/** URL to load in the window. */
url: string,
/** Additional options for opening. */
options: OpenOptions
): Promise<Window>;