Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import { describe, it, expect } from '@jest/globals';
import { describe, it } from '@jest/globals';
import { execFileSync } from 'node:child_process';
import path from 'node:path';

import { maestro } from '../../utils/maestro';

/**
* Prints the texts on screen, including the WebView page's own text, so a failure
* shows how far the trace got: "(none โ€” not injected)" means the page never saw the
* injected meta tag, "(readingโ€ฆ)" means the page script never ran, and a trace value
* in the page means the readback was not delivered to or not matched in React Native.
*/
function printScreenTexts(): void {
try {
const hierarchy = execFileSync('maestro', ['hierarchy'], {
cwd: path.join(__dirname, '../..'),
encoding: 'utf8',
maxBuffer: 64 * 1024 * 1024,
timeout: 120000,
});
// In screen order: the React Native panel first, then the WebView page.
const texts = [...hierarchy.matchAll(/"(?:text|accessibilityText|hintText)"\s*:\s*"([^"]+)"/g)].map(
match => match[1],
);
console.log('Screen texts after the WebView flow failed:\n' + texts.join('\n'));
} catch (e) {
console.log('Could not read the screen hierarchy:', e);
}
}

describe('WebView trace connection', () => {
it('injects the React Native trace into the WebView, which reads it back', async () => {
// The check runs on-device in the Maestro flow: it opens the WebView demo
// screen and asserts the "WebView trace connected" status becomes visible,
// which only happens when the page reads back the injected `sentry-trace`
// meta tag and it matches the trace active in React Native. A failed
// injection makes the flow exit non-zero, rejecting this promise.
await expect(
maestro('tests/webViewTraceConnection/webViewTraceConnection.test.yml'),
).resolves.toBeUndefined();
try {
await maestro('tests/webViewTraceConnection/webViewTraceConnection.test.yml');
} catch (error) {
printScreenTexts();
throw error;
}
}, 240000);
});
25 changes: 15 additions & 10 deletions samples/react-native/src/Screens/WebviewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ function buildDemoPage(dsn: string): string {
<html>
<head>
<meta charset="utf-8" />
<script src="https://browser.sentry-cdn.com/${SDK_VERSION}/bundle.tracing.min.js" crossorigin="anonymous"></script>
<script>
// browserTracingIntegration reads the injected sentry-trace/baggage meta tags
// on pageload and continues the trace. Guarded so a failed CDN load (offline)
// doesn't break the page's own trace readback below.
if (window.Sentry) {
Sentry.init({
dsn: ${JSON.stringify(dsn)},
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
release: 'webview-demo',
environment: 'dev',
});
// doesn't break the page.
function initSentry() {
if (window.Sentry) {
Sentry.init({
dsn: ${JSON.stringify(dsn)},
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
release: 'webview-demo',
environment: 'dev',
});
}
}
</script>
<!-- Loaded async: a blocking script would hold back the page's own trace readback
below until the CDN responds, so a slow or unreachable network (as on CI
emulators) left the page stuck instead of reporting the injected trace. -->
<script async src="https://browser.sentry-cdn.com/${SDK_VERSION}/bundle.tracing.min.js" crossorigin="anonymous" onload="initSentry()"></script>
</head>
<body style="font-family: -apple-system, system-ui, sans-serif; padding: 20px;">
<h3>WebView page</h3>
Expand Down
Loading