Skip to content

Commit d9b5495

Browse files
committed
safari working
1 parent b9e0ac0 commit d9b5495

File tree

4 files changed

+531
-63
lines changed

4 files changed

+531
-63
lines changed

chrome.txt

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
> @optimizely/[email protected] test-vitest-browser
3+
> node ./scripts/run-browser-tests.js
4+
5+
[[email protected]] injecting env (1) from .env -- tip: ⚙️ specify custom .env file path with { path: '/custom/path/.env' }
6+
Starting BrowserStack Local tunnel...
7+
BrowserStack Local tunnel started successfully
8+
Local Identifier: 75719
9+
Waiting for tunnel to establish...
10+
Tunnel ready!
11+
12+
================================================================================
13+
Running tests on BrowserStack (Chrome 102, Firefox 91, Edge 84, Safari 13.1, Opera 76)...
14+
================================================================================
15+
16+
> @optimizely/[email protected] test-vitest
17+
> vitest run --config vitest.browser.config.mts
18+
19+
[[email protected]] injecting env (0) from .env -- tip: 🔐 encrypt with Dotenvx: https://dotenvx.com
20+
21+
RUN v3.2.4 /Users/raju.ahmed/workspace/javascript-sdk
22+
23+
onInit - Browser test session starting
24+
[[email protected]] injecting env (0) from .env -- tip: ⚙️ enable debug logging with { debug: true }
25+
✓ TS |chrome| lib/entrypoint.test-d.ts (0 test)
26+
✓ TS |chrome| lib/entrypoint.universal.test-d.ts (0 test)
27+
28+
[BROWSER LOG] 2025-12-18T10:30:14.027Z
29+
[Debug] window.__vitest_browser_runner__: undefined undefined
30+
31+
[BROWSER LOG] 2025-12-18T10:30:14.024Z
32+
[Console Capture] Initialized successfully
33+
34+
[BROWSER LOG] 2025-12-18T10:30:14.201Z
35+
entry url >>>>>>>>>>>>>>>>> ws://localhost:63315/__vitest_browser_api__?type=orchestrator&rpcId=96e1a0c1-accd-463f-90e4-b35b32a5b667&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=orchestrate&token=616b325d-718f-4789-a822-3f7dff96c3ff
36+
37+
[BROWSER LOG] 2025-12-18T10:30:14.203Z
38+
[WebSocket] Connecting to: ws://localhost:63315/__vitest_browser_api__?type=orchestrator&rpcId=96e1a0c1-accd-463f-90e4-b35b32a5b667&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=orchestrate&token=616b325d-718f-4789-a822-3f7dff96c3ff
39+
40+
[BROWSER LOG] 2025-12-18T10:30:14.459Z
41+
[WebSocket] Connection OPENED: ws://localhost:63315/__vitest_browser_api__?type=orchestrator&rpcId=96e1a0c1-accd-463f-90e4-b35b32a5b667&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=orchestrate&token=616b325d-718f-4789-a822-3f7dff96c3ff
42+
43+
[BROWSER LOG] 2025-12-18T10:30:14.580Z
44+
[WebSocket] Connecting to: ws://localhost:63315/?token=uJ_nizGnNtU8
45+
46+
[BROWSER LOG] 2025-12-18T10:30:14.703Z
47+
[WebSocket] Connecting to: ws://localhost:63315/__vitest_api__?token=616b325d-718f-4789-a822-3f7dff96c3ff
48+
49+
[BROWSER LOG] 2025-12-18T10:30:14.990Z
50+
[WebSocket] Connection OPENED: ws://localhost:63315/?token=uJ_nizGnNtU8
51+
52+
[BROWSER LOG] 2025-12-18T10:30:14.992Z
53+
[WebSocket] Connection OPENED: ws://localhost:63315/__vitest_api__?token=616b325d-718f-4789-a822-3f7dff96c3ff
54+
55+
[BROWSER LOG] 2025-12-18T10:30:16.168Z
56+
[Console Capture] Initialized successfully
57+
58+
[BROWSER LOG] 2025-12-18T10:30:16.170Z
59+
[Debug] window.__vitest_browser_runner__: object {"moduleCache":{},"cleanups":[],"config":{"mode":"test","isolate":false,"defines":{},"setupFiles":["/Users/raju.ahmed/workspace/javascript-sdk/vitest.setup.ts"],"allowOnly":true,"testTimeout":120000,"hookTimeout":120000,"clearMocks":false,"mockReset":false,"restoreMocks":false,"unstubEnvs":false,"unstubGlobals":false,"maxConcurrency":5,"pool":"forks","expect":{},"snapshotSerializers":[],"disableConsoleIntercept":false,"root":"/Users/raju.ahmed/workspace/javascript-sdk","name":"chrome","globals":false,"coverage":{"reportsDirectory":"./coverage","provider":"v8","enabled":false,"htmlReporter":{}},"fakeTimers":{"loopLimit":10000,"shouldClearNativeTimers":true},"poolOptions":{"forks":{"singleFork":false,"isolate":false},"threads":{"singleThread":false,"isolate":false},"vmThreads":{"singleThread":false},"vmForks":{"singleFork":false}},"deps":{"web":{"transformAssets":true,"transformCss":true,"transformGlobPattern":[]},"optimizer":{"web":{"enabled":true},"ssr":{"enabled":true}},"moduleDirectories":["/node_modules/"]},"snapshotOptions":{"updateSnapshot":"new","snapshotFormat":{},"expand":false},"sequence":{"hooks":"stack"},"inspector":{"enabled":false,"waitForDebugger":false},"watch":false,"includeTaskLocation":true,"env":{"BASE_URL":"/","MODE":"test","DEV":true,"PROD":false,"VITEST_BROWSER_DEBUG":""},"browser":{"name":"chrome","headless":false,"isolate":true,"fileParallelism":true,"ui":true,"viewport":{"width":414,"height":896},"screenshotFailures":false,"locators":{"testIdAttribute":"data-testid"},"providerOptions":{}}},"viteConfig":{"root":"/Users/raju.ahmed/workspace/javascript-sdk"},"type":"tester","sessionId":"96e1a0c1-accd-463f-90e4-b35b32a5b667","testerId":"19b34b77-86a5-448f-8774-1d7fc1bff13a","provider":"webdriverio","method":"none","providedContext":{},"cdp":{}}
60+
61+
[BROWSER LOG] 2025-12-18T10:30:16.173Z
62+
[WebSocket] Connecting to: ws://localhost:63315/?token=uJ_nizGnNtU8
63+
64+
[BROWSER LOG] 2025-12-18T10:30:16.509Z
65+
[WebSocket] Connection OPENED: ws://localhost:63315/?token=uJ_nizGnNtU8
66+
67+
[BROWSER LOG] 2025-12-18T10:30:19.778Z
68+
[WebSocket] Connecting to: ws://localhost:63315/__vitest_browser_api__?type=tester&rpcId=19b34b77-86a5-448f-8774-1d7fc1bff13a&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=none&token=616b325d-718f-4789-a822-3f7dff96c3ff
69+
70+
[BROWSER LOG] 2025-12-18T10:30:19.777Z
71+
entry url >>>>>>>>>>>>>>>>> ws://localhost:63315/__vitest_browser_api__?type=tester&rpcId=19b34b77-86a5-448f-8774-1d7fc1bff13a&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=none&token=616b325d-718f-4789-a822-3f7dff96c3ff
72+
73+
[BROWSER WARN] 2025-12-18T10:30:19.795Z
74+
Module "util" has been externalized for browser compatibility. Cannot access "util.inspect" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
75+
76+
[BROWSER LOG] 2025-12-18T10:30:20.015Z
77+
[WebSocket] Connection OPENED: ws://localhost:63315/__vitest_browser_api__?type=tester&rpcId=19b34b77-86a5-448f-8774-1d7fc1bff13a&sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&projectName=chrome&method=none&token=616b325d-718f-4789-a822-3f7dff96c3ff
78+
[stdout] ================================================================================
79+
stdout | lib/event_processor/event_builder/user_event.spec.ts
80+
================================================================================
81+
[stdout] Vitest Browser Session ID (global): unknown
82+
stdout | lib/event_processor/event_builder/user_event.spec.ts
83+
Vitest Browser Session ID (global): unknown
84+
[stdout] Vitest Browser Session ID (URL): 96e1a0c1-accd-463f-90e4-b35b32a5b667
85+
stdout | lib/event_processor/event_builder/user_event.spec.ts
86+
Vitest Browser Session ID (URL): 96e1a0c1-accd-463f-90e4-b35b32a5b667
87+
[stdout] User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
88+
stdout | lib/event_processor/event_builder/user_event.spec.ts
89+
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
90+
[stdout] Location: http://localhost:63315/?sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&iframeId=/Users/raju.ahmed/workspace/javascript-sdk/lib/event_processor/event_builder/user_event.spec.ts
91+
stdout | lib/event_processor/event_builder/user_event.spec.ts
92+
Location: http://localhost:63315/?sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&iframeId=/Users/raju.ahmed/workspace/javascript-sdk/lib/event_processor/event_builder/user_event.spec.ts
93+
[stdout] ================================================================================
94+
stdout | lib/event_processor/event_builder/user_event.spec.ts
95+
================================================================================
96+
97+
[BROWSER LOG] 2025-12-18T10:30:22.203Z
98+
================================================================================
99+
100+
[BROWSER LOG] 2025-12-18T10:30:22.206Z
101+
Vitest Browser Session ID (global): unknown
102+
103+
[BROWSER LOG] 2025-12-18T10:30:22.210Z
104+
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
105+
106+
[BROWSER LOG] 2025-12-18T10:30:22.208Z
107+
Vitest Browser Session ID (URL): 96e1a0c1-accd-463f-90e4-b35b32a5b667
108+
109+
[BROWSER LOG] 2025-12-18T10:30:22.215Z
110+
================================================================================
111+
✓ |chrome| lib/event_processor/event_builder/user_event.spec.ts (2 tests) 22ms
112+
113+
[BROWSER LOG] 2025-12-18T10:30:22.212Z
114+
Location: http://localhost:63315/?sessionId=96e1a0c1-accd-463f-90e4-b35b32a5b667&iframeId=/Users/raju.ahmed/workspace/javascript-sdk/lib/event_processor/event_builder/user_event.spec.ts
115+
116+
Test Files 3 passed (3)
117+
Tests 2 passed (2)
118+
Type Errors no errors
119+
Start at 16:29:59
120+
Duration 20.64s (transform 0ms, setup 124ms, collect 1.80s, tests 22ms, environment 0ms, prepare 14.16s, typecheck 1.37s)
121+
122+
123+
✓ All browser tests passed!
124+
125+
================================================================================
126+
Browser test summary:
127+
================================================================================
128+
All browser tests passed!
129+
BrowserStack Local tunnel stopped

public/console-capture.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Capture all console methods and send to server
2+
(function() {
3+
const originalConsole = {
4+
log: console.log,
5+
error: console.error,
6+
warn: console.warn,
7+
info: console.info
8+
};
9+
10+
['log', 'error', 'warn', 'info'].forEach(method => {
11+
console[method] = function(...args) {
12+
// Send to server via fetch
13+
fetch('/__vitest_console__', {
14+
method: 'POST',
15+
headers: { 'Content-Type': 'application/json' },
16+
body: JSON.stringify({
17+
type: method,
18+
message: args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' '),
19+
timestamp: Date.now()
20+
})
21+
}).catch(() => {});
22+
23+
// Call original
24+
originalConsole[method].apply(console, args);
25+
};
26+
});
27+
28+
// Capture uncaught errors
29+
window.addEventListener('error', (e) => {
30+
fetch('/__vitest_console__', {
31+
method: 'POST',
32+
headers: { 'Content-Type': 'application/json' },
33+
body: JSON.stringify({
34+
type: 'error',
35+
message: 'Uncaught: ' + e.message + ' at ' + e.filename + ':' + e.lineno,
36+
timestamp: Date.now()
37+
})
38+
}).catch(() => {});
39+
});
40+
41+
// Capture unhandled promise rejections
42+
window.addEventListener('unhandledrejection', (e) => {
43+
fetch('/__vitest_console__', {
44+
method: 'POST',
45+
headers: { 'Content-Type': 'application/json' },
46+
body: JSON.stringify({
47+
type: 'error',
48+
message: 'Unhandled Promise Rejection: ' + (e.reason?.message || e.reason),
49+
timestamp: Date.now()
50+
})
51+
}).catch(() => {});
52+
});
53+
54+
// Log that capture is active
55+
console.log('[Console Capture] Initialized successfully');
56+
57+
// Debug: Check if Vitest browser globals are set
58+
console.log('[Debug] window.__vitest_browser_runner__:', typeof window.__vitest_browser_runner__, window.__vitest_browser_runner__);
59+
60+
// Intercept XMLHttpRequest to log headers for __vitest_api__ requests
61+
// const OriginalXMLHttpRequest = window.XMLHttpRequest;
62+
// window.XMLHttpRequest = function() {
63+
// const xhr = new OriginalXMLHttpRequest();
64+
// const originalOpen = xhr.open;
65+
// const originalSetRequestHeader = xhr.setRequestHeader;
66+
// const originalSend = xhr.send;
67+
68+
// let requestUrl = '';
69+
// let requestMethod = '';
70+
// const requestHeaders = {};
71+
72+
// xhr.open = function(method, url, ...args) {
73+
// requestUrl = url;
74+
// requestMethod = method;
75+
// if (url.includes('__vitest_api__')) {
76+
// console.log('[XHR BROWSER] Opening request:', method, url);
77+
// }
78+
// return originalOpen.apply(this, [method, url, ...args]);
79+
// };
80+
81+
// xhr.setRequestHeader = function(header, value) {
82+
// requestHeaders[header] = value;
83+
// if (requestUrl.includes('__vitest_api__')) {
84+
// console.log('[XHR BROWSER] Setting header:', header, '=', value);
85+
// }
86+
// return originalSetRequestHeader.apply(this, arguments);
87+
// };
88+
89+
// xhr.send = function(...args) {
90+
// if (requestUrl.includes('__vitest_api__')) {
91+
// console.log('[XHR BROWSER] Sending request to:', requestUrl);
92+
// console.log('[XHR BROWSER] All request headers:', JSON.stringify(requestHeaders, null, 2));
93+
// }
94+
// return originalSend.apply(this, args);
95+
// };
96+
97+
// return xhr;
98+
// };
99+
100+
// Intercept fetch API to log headers for __vitest_api__ requests
101+
// const originalFetch = window.fetch;
102+
// window.fetch = function(url, options) {
103+
// if (url.includes && url.includes('__vitest_api__')) {
104+
// console.log('[FETCH BROWSER] Request URL:', url);
105+
// console.log('[FETCH BROWSER] Request options:', JSON.stringify(options, null, 2));
106+
// if (options && options.headers) {
107+
// console.log('[FETCH BROWSER] Request headers:', JSON.stringify(options.headers, null, 2));
108+
// }
109+
// }
110+
// return originalFetch.apply(this, arguments);
111+
// };
112+
113+
// Intercept WebSocket constructor to log connection attempts and status changes
114+
const OriginalWebSocket = window.WebSocket;
115+
window.WebSocket = function(url, protocols) {
116+
// Log the connection request with full URL including protocol
117+
const fullUrl = url.startsWith('ws://') || url.startsWith('wss://')
118+
? url
119+
: (window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + url;
120+
121+
console.log('[WebSocket] Connecting to:', fullUrl);
122+
123+
try {
124+
const ws = new OriginalWebSocket(url, protocols);
125+
126+
// Log connection status change events
127+
ws.addEventListener('open', () => {
128+
console.log('[WebSocket] Connection OPENED:', fullUrl);
129+
});
130+
131+
ws.addEventListener('error', () => {
132+
console.log('[WebSocket] Connection ERROR:', fullUrl);
133+
});
134+
135+
ws.addEventListener('close', (event) => {
136+
console.log('[WebSocket] Connection CLOSED:', fullUrl, '- Code:', event.code, '- Reason:', event.reason || '(none)');
137+
});
138+
139+
return ws;
140+
} catch (error) {
141+
console.error('[WebSocket] Failed to create connection:', fullUrl, error);
142+
throw error;
143+
}
144+
};
145+
window.WebSocket.prototype = OriginalWebSocket.prototype;
146+
})();

0 commit comments

Comments
 (0)