Wren a web browser where WebAssembly runs everything, JavaScript included

Module ext

The transport of browser extensions (docs/extensions.md, section 3.9; src/page/ext_realm.odin, ext_router.odin; native/js/odin/ext_runtime.odin and ext_api.js build chrome.* on it; the namespaces are described in api/ext_<namespace>.widl). The host derives the extension and the kind of context from the realm that calls (a guest sends no identity): in a realm that is not an extension context every function answers nothing ("" , a rejected call, no effect). Payloads are JSON text, as Chrome's messages are, and are bounded by extensions.message.max_bytes.

Exposed to: Window, Worker. Source: api/ext.widl.

Odin: import "wren:ext".

Functions

Ext_info

string Ext_info()

The realm's context as a JSON object ("" : not an extension context): id, kind (background, popup, tab), base URL, UI language, flavour, the API methods, events and local members this context may use (its permissions and its kind decide them), and the constants of its namespaces.

Odin: ext.info.

Host: Ext_info :: proc(c: ^Call) -> string

Ext_manifest

string Ext_manifest()

runtime.getManifest(): the manifest as JSON text, comments removed and MSG_* replaced.

Odin: ext.manifest.

Host: Ext_manifest :: proc(c: ^Call) -> string

Ext_message

string Ext_message(string name, string subs)

i18n.getMessage(name, substitutions): subs is a JSON list of strings. "" when no catalogue has the message.

Odin: ext.message.

Host: Ext_message :: proc(c: ^Call, name: string, subs: string) -> string

Ext_call

Promise Ext_call(string method, string args)

An API call (method as "storage.local.get", args a JSON list): a promise of the answer as text: a JSON value, "" for undefined, or "!" followed by the error's message (runtime.lastError).

Odin: ext.call.

Host: Ext_call :: proc(c: ^Call, method: string, args: string) -> u64

Ext_listen

void Ext_listen(string event, bool on)

The realm added a listener of event ("runtime.onMessage"), or removed its last one (on false): an event nobody listens to is not sent, and a stopped background does not start for it.

Odin: ext.listen.

Host: Ext_listen :: proc(c: ^Call, event: string, on: bool)

Ext_take

string Ext_take()

The next event for this realm as a JSON object ("" : none waits): {t: "event", e, a, r}, {t: "connect", p, n, s}, {t: "port", p, m}, {t: "disconnect", p}. The host calls the realm's wj_ext_event when one arrives.

Odin: ext.take.

Host: Ext_take :: proc(c: ^Call) -> string

Ext_respond

void Ext_respond(u64 reply, string value, bool has)

The answer of this realm to message reply (runtime.onMessage): has false when its listeners gave none.

Odin: ext.respond.

Host: Ext_respond :: proc(c: ^Call, reply: u64, value: string, has: bool)

Ext_connect

void Ext_connect(u64 port, string name)

runtime.connect: a port this realm opens, id port (its own choice), named name, to the other contexts of its extension that listen to runtime.onConnect.

Odin: ext.connect.

Host: Ext_connect :: proc(c: ^Call, port: u64, name: string)

Ext_connectTab

void Ext_connectTab(u64 port, string name, i64 tab, i64 frame)

tabs.connect: a port this realm opens, id port (its own choice), named name, to the content scripts of its extension in tab tab that listen to runtime.onConnect: in frame frame only, or in every frame when it is -1.

Odin: ext.connectTab.

Host: Ext_connectTab :: proc(c: ^Call, port: u64, name: string, tab: i64, frame: i64)

Ext_portPost

void Ext_portPost(u64 port, string message)

Port.postMessage: message (JSON text) to the other end(s) of port.

Odin: ext.portPost.

Host: Ext_portPost :: proc(c: ^Call, port: u64, message: string)

Ext_portClose

void Ext_portClose(u64 port)

Port.disconnect: the other end(s) get onDisconnect.

Odin: ext.portClose.

Host: Ext_portClose :: proc(c: ^Call, port: u64)

Edit this page on GitHub