Skip to content

Commit b46674c

Browse files
fix(utils): use apply in console instrumentation (#4568)
Co-authored-by: Katie Byers <lobsterkatie@gmail.com>
1 parent 9e87bf9 commit b46674c

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable no-console */
2+
import { ConsoleMessage, expect } from '@playwright/test';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
6+
// Regression test against https://github.com/getsentry/sentry-javascript/issues/4558
7+
sentryTest('should not change console output', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
// https://playwright.dev/docs/api/class-page#page-event-console
11+
page.on('console', (msg: ConsoleMessage) => {
12+
expect(msg.text()).toEqual(`hello world ${msg.type()}`);
13+
});
14+
15+
await page.goto(url);
16+
17+
await page.evaluate(() => console.log('hello', 'world', 'log'));
18+
19+
await page.evaluate(() => console.warn('hello', 'world', 'warning'));
20+
21+
await page.evaluate(() => console.debug('hello', 'world', 'debug'));
22+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
7+
</head>
8+
<body>
9+
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
10+
</body>
11+
</html>

packages/integrations/src/captureconsole.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class CaptureConsole implements Integration {
7272

7373
// this fails for some browsers. :(
7474
if (originalConsoleMethod) {
75-
originalConsoleMethod.call(global.console, args);
75+
originalConsoleMethod.apply(global.console, args);
7676
}
7777
});
7878
});

packages/utils/src/instrument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function instrumentConsole(): void {
122122

123123
// this fails for some browsers. :(
124124
if (originalConsoleMethod) {
125-
originalConsoleMethod.call(global.console, args);
125+
originalConsoleMethod.apply(global.console, args);
126126
}
127127
};
128128
});

0 commit comments

Comments
 (0)