Skip to content

Commit b93e10c

Browse files
authored
🤖 Merge PR DefinitelyTyped#72037 updated types for webextension-polyfill by @Lusito
1 parent 6f893a9 commit b93e10c

File tree

6 files changed

+80
-90
lines changed

6 files changed

+80
-90
lines changed

types/webextension-polyfill/namespaces/activityLog.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export namespace ActivityLog {
8888
/**
8989
* Receives an activityItem for each logging event.
9090
*/
91-
interface onExtensionActivityEvent extends Events.Event<(details: OnExtensionActivityDetailsType) => void> {
91+
interface OnExtensionActivityEvent extends Events.Event<(details: OnExtensionActivityDetailsType) => void> {
9292
/**
9393
* Registers an event listener <em>callback</em> to an event.
9494
*
@@ -101,6 +101,6 @@ export namespace ActivityLog {
101101
/**
102102
* Receives an activityItem for each logging event.
103103
*/
104-
onExtensionActivity: onExtensionActivityEvent;
104+
onExtensionActivity: OnExtensionActivityEvent;
105105
}
106106
}

types/webextension-polyfill/namespaces/proxy.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export namespace Proxy {
184184
/**
185185
* Fired when proxy data is needed for a request.
186186
*/
187-
interface onRequestEvent extends Events.Event<(details: OnRequestDetailsType) => void> {
187+
interface OnRequestEvent extends Events.Event<(details: OnRequestDetailsType) => void> {
188188
/**
189189
* Registers an event listener <em>callback</em> to an event.
190190
*
@@ -203,7 +203,7 @@ export namespace Proxy {
203203
/**
204204
* Fired when proxy data is needed for a request.
205205
*/
206-
onRequest: onRequestEvent;
206+
onRequest: OnRequestEvent;
207207

208208
/**
209209
* Notifies about errors caused by the invalid use of the proxy API.

types/webextension-polyfill/namespaces/runtime.d.ts

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@ export namespace Runtime {
262262
*/
263263
type OnPerformanceWarningSeverity = "low" | "medium" | "high";
264264

265+
/**
266+
* The third parameter is a function to call (at most once) when you have a response.
267+
* The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code>
268+
* listener in the same document, then only one may send a response. <code>sendResponse</code>
269+
* becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to
270+
* send a response asynchronously (this will keep the message channel open to the other end until <code>sendResponse</code>
271+
* is called).
272+
*/
273+
type OnMessageListenerCallback = (
274+
message: unknown,
275+
sender: MessageSender,
276+
sendResponse: (response: unknown) => void,
277+
) => true;
278+
279+
/**
280+
* The return value should be a promise of any JSON-ifiable object. If you have more than one <code>onMessage</code>
281+
* listener in the same document, then only one may send a response.
282+
*/
283+
type OnMessageListenerAsync = (message: unknown, sender: MessageSender) => Promise<unknown>;
284+
285+
type OnMessageListenerNoResponse = (message: unknown, sender: MessageSender) => void;
286+
287+
type OnMessageListener = OnMessageListenerCallback | OnMessageListenerAsync | OnMessageListenerNoResponse;
288+
265289
/**
266290
* If an update is available, this contains more information about the available update.
267291
*/
@@ -579,53 +603,18 @@ export namespace Runtime {
579603

580604
/**
581605
* Fired when a message is sent from either an extension process or a content script.
582-
*
583-
* @param message Optional. The message sent by the calling script.
584-
* @param sendResponse Function to call (at most once) when you have a response. This is an alternative to returning a
585-
* Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code>
586-
* listener in the same document, then only one may send a response. This function becomes invalid when the event listener
587-
* returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this
588-
* will keep the message channel open to the other end until <code>sendResponse</code> is called).
589-
*/
590-
onMessage: Events.Event<
591-
(
592-
message: unknown,
593-
sender: MessageSender,
594-
sendResponse: (message: unknown) => void,
595-
) => Promise<unknown> | true | undefined
596-
>;
606+
*/
607+
onMessage: Events.Event<OnMessageListener>;
597608

598609
/**
599610
* Fired when a message is sent from another extension/app. Cannot be used in a content script.
600-
*
601-
* @param message Optional. The message sent by the calling script.
602-
* @param sendResponse Function to call (at most once) when you have a response. This is an alternative to returning a
603-
* Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code>
604-
* listener in the same document, then only one may send a response. This function becomes invalid when the event listener
605-
* returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this
606-
* will keep the message channel open to the other end until <code>sendResponse</code> is called).
607-
*/
608-
onMessageExternal: Events.Event<
609-
(
610-
message: unknown,
611-
sender: MessageSender,
612-
sendResponse: (message: unknown) => void,
613-
) => Promise<unknown> | true | undefined
614-
>;
611+
*/
612+
onMessageExternal: Events.Event<OnMessageListener>;
615613

616614
/**
617615
* Fired when a message is sent from a USER_SCRIPT world registered through the userScripts API.
618-
*
619-
* @param message Optional. The message sent by the calling script.
620-
* @param sendResponse Function to call (at most once) when you have a response. The argument should be any JSON-ifiable
621-
* object. If you have more than one <code>onMessage</code> listener in the same document,
622-
* then only one may send a response. This function becomes invalid when the event listener returns,
623-
* unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep
624-
* the message channel open to the other end until <code>sendResponse</code> is called).
625-
*/
626-
onUserScriptMessage: Events.Event<
627-
(message: unknown, sender: MessageSender, sendResponse: () => void) => boolean | undefined
628-
>;
616+
*/
617+
onUserScriptMessage: Events.Event<OnMessageListener>;
629618

630619
/**
631620
* Fired when a runtime performance issue is detected with the extension. Observe this event to be proactively notified of

types/webextension-polyfill/namespaces/tabs.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ export namespace Tabs {
10521052
/**
10531053
* Fired when a tab is updated.
10541054
*/
1055-
interface onUpdatedEvent
1055+
interface OnUpdatedEvent
10561056
extends Events.Event<(tabId: number, changeInfo: OnUpdatedChangeInfoType, tab: Tab) => void>
10571057
{
10581058
/**
@@ -1406,7 +1406,7 @@ export namespace Tabs {
14061406
/**
14071407
* Fired when a tab is updated.
14081408
*/
1409-
onUpdated: onUpdatedEvent;
1409+
onUpdated: OnUpdatedEvent;
14101410

14111411
/**
14121412
* Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved.

types/webextension-polyfill/namespaces/webNavigation.d.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export namespace WebNavigation {
350350
/**
351351
* Fired when a navigation is about to occur.
352352
*/
353-
interface onBeforeNavigateEvent extends Events.Event<(details: OnBeforeNavigateDetailsType) => void> {
353+
interface OnBeforeNavigateEvent extends Events.Event<(details: OnBeforeNavigateDetailsType) => void> {
354354
/**
355355
* Registers an event listener <em>callback</em> to an event.
356356
*
@@ -366,7 +366,7 @@ export namespace WebNavigation {
366366
* might still be downloading, but at least part of the document has been received from the server and the browser has
367367
* decided to switch to the new document.
368368
*/
369-
interface onCommittedEvent extends Events.Event<(details: OnCommittedDetailsType) => void> {
369+
interface OnCommittedEvent extends Events.Event<(details: OnCommittedDetailsType) => void> {
370370
/**
371371
* Registers an event listener <em>callback</em> to an event.
372372
*
@@ -380,7 +380,7 @@ export namespace WebNavigation {
380380
/**
381381
* Fired when the page's DOM is fully constructed, but the referenced resources may not finish loading.
382382
*/
383-
interface onDOMContentLoadedEvent extends Events.Event<(details: OnDOMContentLoadedDetailsType) => void> {
383+
interface OnDOMContentLoadedEvent extends Events.Event<(details: OnDOMContentLoadedDetailsType) => void> {
384384
/**
385385
* Registers an event listener <em>callback</em> to an event.
386386
*
@@ -394,7 +394,7 @@ export namespace WebNavigation {
394394
/**
395395
* Fired when a document, including the resources it refers to, is completely loaded and initialized.
396396
*/
397-
interface onCompletedEvent extends Events.Event<(details: OnCompletedDetailsType) => void> {
397+
interface OnCompletedEvent extends Events.Event<(details: OnCompletedDetailsType) => void> {
398398
/**
399399
* Registers an event listener <em>callback</em> to an event.
400400
*
@@ -409,7 +409,7 @@ export namespace WebNavigation {
409409
* Fired when an error occurs and the navigation is aborted. This can happen if either a network error occurred,
410410
* or the user aborted the navigation.
411411
*/
412-
interface onErrorOccurredEvent extends Events.Event<(details: OnErrorOccurredDetailsType) => void> {
412+
interface OnErrorOccurredEvent extends Events.Event<(details: OnErrorOccurredDetailsType) => void> {
413413
/**
414414
* Registers an event listener <em>callback</em> to an event.
415415
*
@@ -423,7 +423,7 @@ export namespace WebNavigation {
423423
/**
424424
* Fired when a new window, or a new tab in an existing window, is created to host a navigation.
425425
*/
426-
interface onCreatedNavigationTargetEvent
426+
interface OnCreatedNavigationTargetEvent
427427
extends Events.Event<(details: OnCreatedNavigationTargetDetailsType) => void>
428428
{
429429
/**
@@ -439,7 +439,7 @@ export namespace WebNavigation {
439439
/**
440440
* Fired when the reference fragment of a frame was updated. All future events for that frame will use the updated URL.
441441
*/
442-
interface onReferenceFragmentUpdatedEvent
442+
interface OnReferenceFragmentUpdatedEvent
443443
extends Events.Event<(details: OnReferenceFragmentUpdatedDetailsType) => void>
444444
{
445445
/**
@@ -458,7 +458,7 @@ export namespace WebNavigation {
458458
/**
459459
* Fired when the frame's history was updated to a new URL. All future events for that frame will use the updated URL.
460460
*/
461-
interface onHistoryStateUpdatedEvent extends Events.Event<(details: OnHistoryStateUpdatedDetailsType) => void> {
461+
interface OnHistoryStateUpdatedEvent extends Events.Event<(details: OnHistoryStateUpdatedDetailsType) => void> {
462462
/**
463463
* Registers an event listener <em>callback</em> to an event.
464464
*
@@ -488,40 +488,40 @@ export namespace WebNavigation {
488488
/**
489489
* Fired when a navigation is about to occur.
490490
*/
491-
onBeforeNavigate: onBeforeNavigateEvent;
491+
onBeforeNavigate: OnBeforeNavigateEvent;
492492

493493
/**
494494
* Fired when a navigation is committed. The document (and the resources it refers to, such as images and subframes)
495495
* might still be downloading, but at least part of the document has been received from the server and the browser has
496496
* decided to switch to the new document.
497497
*/
498-
onCommitted: onCommittedEvent;
498+
onCommitted: OnCommittedEvent;
499499

500500
/**
501501
* Fired when the page's DOM is fully constructed, but the referenced resources may not finish loading.
502502
*/
503-
onDOMContentLoaded: onDOMContentLoadedEvent;
503+
onDOMContentLoaded: OnDOMContentLoadedEvent;
504504

505505
/**
506506
* Fired when a document, including the resources it refers to, is completely loaded and initialized.
507507
*/
508-
onCompleted: onCompletedEvent;
508+
onCompleted: OnCompletedEvent;
509509

510510
/**
511511
* Fired when an error occurs and the navigation is aborted. This can happen if either a network error occurred,
512512
* or the user aborted the navigation.
513513
*/
514-
onErrorOccurred: onErrorOccurredEvent;
514+
onErrorOccurred: OnErrorOccurredEvent;
515515

516516
/**
517517
* Fired when a new window, or a new tab in an existing window, is created to host a navigation.
518518
*/
519-
onCreatedNavigationTarget: onCreatedNavigationTargetEvent;
519+
onCreatedNavigationTarget: OnCreatedNavigationTargetEvent;
520520

521521
/**
522522
* Fired when the reference fragment of a frame was updated. All future events for that frame will use the updated URL.
523523
*/
524-
onReferenceFragmentUpdated: onReferenceFragmentUpdatedEvent;
524+
onReferenceFragmentUpdated: OnReferenceFragmentUpdatedEvent;
525525

526526
/**
527527
* Fired when the contents of the tab is replaced by a different (usually previously pre-rendered) tab.
@@ -531,6 +531,6 @@ export namespace WebNavigation {
531531
/**
532532
* Fired when the frame's history was updated to a new URL. All future events for that frame will use the updated URL.
533533
*/
534-
onHistoryStateUpdated: onHistoryStateUpdatedEvent;
534+
onHistoryStateUpdated: OnHistoryStateUpdatedEvent;
535535
}
536536
}

0 commit comments

Comments
 (0)