@@ -11,6 +11,9 @@ import {
1111} from './schema.js' ;
1212import { isBeingFramed } from '../../utils.js' ;
1313
14+ /**
15+ * @typedef {import('../../content-feature.js').default } ContentFeature
16+ */
1417/**
1518 * @import { MessagingInterface } from "./schema.js"
1619 * @typedef {Pick<import("../../captured-globals.js"),
@@ -29,10 +32,11 @@ export const ERROR_MSG = 'Did not install Message Bridge';
2932 *
3033 * @param {string } featureName
3134 * @param {string } [token]
35+ * @param {ContentFeature } [context]
3236 * @return {MessagingInterface }
3337 * @throws {Error }
3438 */
35- export function createPageWorldBridge ( featureName , token ) {
39+ export function createPageWorldBridge ( featureName , token , context ) {
3640 /**
3741 * This feature never operates without a featureName or token
3842 */
@@ -90,7 +94,7 @@ export function createPageWorldBridge(featureName, token) {
9094 throw new captured . Error ( ERROR_MSG ) ;
9195 }
9296
93- return createMessagingInterface ( featureName , send , appendToken ) ;
97+ return createMessagingInterface ( featureName , send , appendToken , context ) ;
9498}
9599
96100/**
@@ -105,15 +109,17 @@ function random() {
105109 * @param {string } featureName
106110 * @param {(evt: {name: string} & Record<string, any>) => void } send
107111 * @param {(s: string) => string } appendToken
112+ * @param {ContentFeature } [context]
108113 * @returns {MessagingInterface }
109114 */
110- function createMessagingInterface ( featureName , send , appendToken ) {
115+ function createMessagingInterface ( featureName , send , appendToken , context ) {
111116 return {
112117 /**
113118 * @param {string } method
114119 * @param {Record<string, any> } params
115120 */
116121 notify ( method , params ) {
122+ context ?. log . info ( 'sending notify' , method , params ) ;
117123 send (
118124 new ProxyNotification ( {
119125 method,
@@ -129,6 +135,7 @@ function createMessagingInterface(featureName, send, appendToken) {
129135 * @returns {Promise<any> }
130136 */
131137 request ( method , params ) {
138+ context ?. log . info ( 'sending request' , method , params ) ;
132139 const id = random ( ) ;
133140
134141 send (
@@ -143,6 +150,7 @@ function createMessagingInterface(featureName, send, appendToken) {
143150 return new Promise ( ( resolve , reject ) => {
144151 const responseName = appendToken ( ProxyResponse . NAME + '-' + id ) ;
145152 const handler = ( /** @type {CustomEvent<unknown> } */ e ) => {
153+ context ?. log . info ( 'received response' , e . detail ) ;
146154 const response = ProxyResponse . create ( e . detail ) ;
147155 if ( response && response . id === id ) {
148156 if ( 'error' in response && response . error ) {
@@ -164,6 +172,7 @@ function createMessagingInterface(featureName, send, appendToken) {
164172 */
165173 subscribe ( name , callback ) {
166174 const id = random ( ) ;
175+ context ?. log . info ( 'subscribing' , name ) ;
167176
168177 send (
169178 new SubscriptionRequest ( {
@@ -174,6 +183,7 @@ function createMessagingInterface(featureName, send, appendToken) {
174183 ) ;
175184
176185 const handler = ( /** @type {CustomEvent<unknown> } */ e ) => {
186+ context ?. log . info ( 'received subscription response' , e . detail ) ;
177187 const subscriptionEvent = SubscriptionResponse . create ( e . detail ) ;
178188 if ( subscriptionEvent ) {
179189 const { id : eventId , params } = subscriptionEvent ;
0 commit comments