Skip to content

Commit 85864a5

Browse files
committed
fix: add temporary logging
1 parent 40f1c64 commit 85864a5

File tree

3 files changed

+28
-68
lines changed

3 files changed

+28
-68
lines changed

packages/browser-tests/src/browser/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ export async function initBrowser(appPort: number): Promise<void> {
1818

1919
page = await browser.newPage();
2020

21+
// Forward browser console to server logs
22+
page.on('console', msg => {
23+
const type = msg.type();
24+
const text = msg.text();
25+
console.log(`[Browser Console ${type.toUpperCase()}] ${text}`);
26+
});
27+
28+
page.on('pageerror', error => {
29+
console.error('[Browser Page Error]', error.message);
30+
});
31+
2132
await page.goto(`http://localhost:${appPort}/app/index.html`, {
2233
waitUntil: "networkidle",
2334
});

packages/browser-tests/src/server.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async function startServer(port: number = 3000): Promise<void> {
9797

9898
const hasEnrBootstrap = Boolean(process.env.WAKU_ENR_BOOTSTRAP);
9999
const networkConfig: any = {
100-
defaultBootstrap: !hasEnrBootstrap,
100+
defaultBootstrap: false,
101101
...(hasEnrBootstrap && {
102102
discovery: {
103103
dns: true,
@@ -107,14 +107,11 @@ async function startServer(port: number = 3000): Promise<void> {
107107
}),
108108
};
109109

110-
console.log(
111-
`Bootstrap mode: ${hasEnrBootstrap ? "ENR-only (defaultBootstrap=false)" : "default bootstrap (defaultBootstrap=true)"}`,
112-
);
110+
// console.log(
111+
// `Bootstrap mode: ${hasEnrBootstrap ? "ENR-only (defaultBootstrap=false)" : "default bootstrap (defaultBootstrap=true)"}`,
112+
// );
113113
if (hasEnrBootstrap) {
114114
console.log(`ENR bootstrap peers: ${process.env.WAKU_ENR_BOOTSTRAP}`);
115-
console.log(
116-
`Discovery options: peerExchange=true, dns=false, peerCache=true`,
117-
);
118115
}
119116

120117
networkConfig.networkConfig = {

packages/browser-tests/web/index.ts

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class WakuHeadless {
7171
) {
7272
this.waku = null as unknown as LightNode;
7373
this.networkConfig = this.buildNetworkConfig(networkConfig);
74+
console.log("Network config on construction:", this.networkConfig);
7475
this.lightpushNode = lightpushNode || null;
7576
this.enrBootstrap = enrBootstrap || null;
7677

@@ -132,50 +133,6 @@ export class WakuHeadless {
132133
} as NetworkConfig;
133134
}
134135

135-
async pushMessage(
136-
contentTopic: string,
137-
payload: string,
138-
): Promise<SerializableSDKProtocolResult> {
139-
if (!this.waku) {
140-
throw new Error("Waku node not started");
141-
}
142-
143-
let processedPayload: Uint8Array;
144-
try {
145-
const binaryString = atob(payload);
146-
const bytes = new Uint8Array(binaryString.length);
147-
for (let i = 0; i < binaryString.length; i++) {
148-
bytes[i] = binaryString.charCodeAt(i);
149-
}
150-
processedPayload = bytes;
151-
} catch (e) {
152-
processedPayload = new TextEncoder().encode(payload);
153-
}
154-
155-
try {
156-
const lightPush = this.waku.lightPush;
157-
if (!lightPush) {
158-
throw new Error("Lightpush service not available");
159-
}
160-
161-
const encoder = this.waku.createEncoder({ contentTopic });
162-
163-
const result = await lightPush.send(encoder, {
164-
payload: processedPayload,
165-
timestamp: new Date(),
166-
});
167-
168-
const serializableResult = makeSerializable(result);
169-
170-
return serializableResult;
171-
} catch (error) {
172-
console.error("Error sending message via lightpush:", error);
173-
throw new Error(
174-
`Failed to send message: ${error instanceof Error ? error.message : String(error)}`,
175-
);
176-
}
177-
}
178-
179136
async pushMessageV3(
180137
contentTopic: string,
181138
payload: string,
@@ -184,6 +141,9 @@ export class WakuHeadless {
184141
if (!this.waku) {
185142
throw new Error("Waku node not started");
186143
}
144+
console.log("Pushing message via v3 lightpush:", contentTopic, payload, pubsubTopic);
145+
console.log("Waku node:", this.waku);
146+
console.log("Network config:", this.networkConfig);
187147

188148
let processedPayload: Uint8Array;
189149
try {
@@ -204,6 +164,9 @@ export class WakuHeadless {
204164
}
205165

206166
const encoder = this.waku.createEncoder({ contentTopic });
167+
console.log("Encoder:", encoder);
168+
console.log("Pubsub topic:", pubsubTopic);
169+
console.log("Encoder pubsub topic:", encoder.pubsubTopic);
207170

208171
if (pubsubTopic && pubsubTopic !== encoder.pubsubTopic) {
209172
console.warn(
@@ -229,6 +192,7 @@ export class WakuHeadless {
229192
);
230193
}
231194
} catch (error) {
195+
console.error("Couldn't send message via preferred lightpush node:", error);
232196
result = await lightPush.send(encoder, {
233197
payload: processedPayload,
234198
timestamp: new Date(),
@@ -290,27 +254,14 @@ export class WakuHeadless {
290254
console.warn("ignore previous waku stop error");
291255
}
292256

293-
if (options.networkConfig) {
294-
this.networkConfig = options.networkConfig;
295-
}
257+
// if (options.networkConfig) {
258+
// this.networkConfig = options.networkConfig;
259+
// console.log("Network config on createWakuNode:", this.networkConfig);
260+
// }
296261

297262
let libp2pConfig: any = {
298263
...options.libp2p,
299264
filterMultiaddrs: false,
300-
connectionManager: {
301-
minConnections: 1,
302-
maxConnections: 50,
303-
connectionGater: {
304-
denyDialPeer: () => false,
305-
denyDialMultiaddr: () => false,
306-
denyInboundConnection: () => false,
307-
denyOutboundConnection: () => false,
308-
denyInboundEncryptedConnection: () => false,
309-
denyOutboundEncryptedConnection: () => false,
310-
denyInboundUpgradedConnection: () => false,
311-
denyOutboundUpgradedConnection: () => false,
312-
},
313-
},
314265
};
315266

316267
if (this.enrBootstrap && this.shouldUseCustomBootstrap(options)) {
@@ -356,6 +307,7 @@ export class WakuHeadless {
356307
await this.waku.dial(this.lightpushNode);
357308
} catch {
358309
// Ignore dial errors
310+
console.warn("Failed to dial preferred lightpush node:", this.lightpushNode);
359311
}
360312
}
361313

0 commit comments

Comments
 (0)