diff --git a/specification/extensions-api/section/events.html b/specification/extensions-api/section/events.html index abfb69a8..a0ded360 100644 --- a/specification/extensions-api/section/events.html +++ b/specification/extensions-api/section/events.html @@ -2,9 +2,10 @@
- Events in this namespace are scoped to a {{ Document }}, - identified by its tab and frame. Each event callback receives a - {{MonetizationInfo}} dictionary describing the affected document. + Events in this namespace are scoped to a [[WebMonetization]] + session. Each event callback receives a + {{monetization/Session}} dictionary identifying the affected + session and the document it belongs to.
- Fired when the first [[WebMonetization]] session becomes active - in a document. Subsequent sessions starting in the same document - do not re-fire this event. + Fired when a [[WebMonetization]] session starts in a document.
callbackThe callback parameter looks like:
(info: {{MonetizationInfo}}) => void
+ (session: {{monetization/Session}}) => void
infosessionbrowser.monetization.onStopped.addListener( +browser.monetization.onStopped.addListener( callback: function, )- Fired when the last [[WebMonetization]] session in a document - has ended. This occurs when the tab is closed, the document - navigates away, or all sessions are explicitly stopped. + Fired when a [[WebMonetization]] session ends. This occurs when + the tab is closed, the document navigates away, or the session + is explicitly stopped.
Parameters
@@ -53,11 +52,11 @@Parameters
callbackThe callback parameter looks like:
(info: {{MonetizationInfo}}) => void
+ (session: {{monetization/Session}}) => void
infosession- For a given document, an {{monetization/onStarted}} event is always - delivered before any corresponding {{monetization/onStopped}} event. - If a document has multiple concurrent sessions, intermediate - session starts and stops do not produce additional events. - Only the transition from zero to one active session - ({{monetization/onStarted}}) and from one to zero active sessions - ({{monetization/onStopped}}) fire events. + For a given session, an {{monetization/onStarted}} event is + always delivered before the corresponding + {{monetization/onStopped}} event. A document with multiple + concurrent sessions receives a separate + {{monetization/onStarted}} and {{monetization/onStopped}} pair + for each session.
browser.monetization.onPayment.addListener( + callback: function, +)+ +
+ Fired when a payment is sent for a monetization session. The + updated budget balance can be retrieved via + {{monetization/getWallet()}}. +
+ +callbackThe callback parameter looks like:
(session: {{monetization/Session}}) => void
+ sessionmonetization namespaceThe monetization namespace is the entry point for the - Web Monetization Extensions API. It exposes events that allow - extensions to observe monetization session state changes within - documents. + Web Monetization Extensions API. It exposes methods for querying + wallet state and budget balance, and events that allow extensions + to observe monetization session lifecycle and payment activity. +
+ +
+ The full chrome.monetization API includes additional
+ methods for wallet connection management and session history that
+ are available only to the browser's built-in WebUI. This
+ specification covers the subset exposed to privileged browser
+ extensions.
[Exposed=Window]
namespace monetization {
+ Promise<Wallet?> getWallet();
+
readonly attribute EventHandler onStarted;
readonly attribute EventHandler onStopped;
+ readonly attribute EventHandler onPayment;
};
+
+
+ Returns the connected user wallet, including its current
+ budget balance. Resolves with null if no wallet
+ is connected.
+
+ Type names defined here are scoped under the + monetization namespace. Implementations expose them as + namespace-scoped dictionaries on `chrome.monetization` + (for example, {{monetization/Wallet}} corresponds to + `chrome.monetization.Wallet`). +
+ +- Describes the document where a monetization state change occurred. + Describes the connected user wallet, including its current + budget balance.
- dictionary MonetizationInfo {
+ enum ReconnectReason {
+ "unauthorized"
+ };
+
+ dictionary Wallet {
+ required DOMString address;
+ required DOMString name;
+ required DOMString currency;
+ required DOMString initialBalance;
+ required DOMString remainingBalance;
+ DOMString? renewDate;
+ ReconnectReason? reconnectReason;
+ };
+
+
+ + The {{Wallet/currency}}, {{Wallet/initialBalance}}, and + {{Wallet/remainingBalance}} members use the same conventions as the + `currency` and `value` members of the {{PaymentCurrencyAmount}} + dictionary defined in [[payment-request]] (and the + `MonetizationCurrencyAmount` interface in [[WebMonetization]]). +
++ Identifies a monetization session and the document it belongs to. +
+ +
+ dictionary Session {
required long tabId;
required long frameId;
- required DOMString url;
+ required long sessionId;
+ required DOMString walletAddress;
};
@@ -26,12 +123,17 @@ 0 denotes the top-level (main) frame.
+ `0` denotes the top-level (main) frame.
+ + Each invocation of this algorithm establishes a new wallet connection. Implementations + that track per-connection payment history SHOULD associate sessions and payments with + the credential record created during this connection, so that balance computations are + scoped to the active connection only. +
Removes all wallet-related state (grant tokens, authentication keys, wallet address details). Budget limits MAY be retained; implementations can also clear {{Storage/maxRateOfPay}} if the user requests a full reset.
++ Implementations that track payment history SHOULD treat each wallet connection as an + independent scope. When a user disconnects and later reconnects (even to the same wallet address), + the new connection starts with a fresh spending balance. Previous connection data MAY be + retained for historical display but MUST NOT affect the active connection's balance computation. +