From 9f1086e715dd6898d7806cfbbf380a47b8a5d308 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 14 Feb 2022 13:19:20 -0500 Subject: [PATCH 1/4] fix(utils): use apply in console instrumentation --- packages/utils/src/instrument.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/instrument.ts b/packages/utils/src/instrument.ts index ec24bc828b60..47d5b5d615e0 100644 --- a/packages/utils/src/instrument.ts +++ b/packages/utils/src/instrument.ts @@ -122,7 +122,7 @@ function instrumentConsole(): void { // this fails for some browsers. :( if (originalConsoleMethod) { - originalConsoleMethod.call(global.console, args); + originalConsoleMethod.apply(global.console, args); } }; }); From a8b0f72a497ed6d4e59ee0e39cbb9c5fd84111cf Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 14 Feb 2022 13:19:53 -0500 Subject: [PATCH 2/4] fix(integrations): use apply in CaptureConsole integration --- packages/integrations/src/captureconsole.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/src/captureconsole.ts b/packages/integrations/src/captureconsole.ts index 9a1cb6534594..3f9076fd7293 100644 --- a/packages/integrations/src/captureconsole.ts +++ b/packages/integrations/src/captureconsole.ts @@ -72,7 +72,7 @@ export class CaptureConsole implements Integration { // this fails for some browsers. :( if (originalConsoleMethod) { - originalConsoleMethod.call(global.console, args); + originalConsoleMethod.apply(global.console, args); } }); }); From 37c330940c27ea01e253a07accfb85b7294331e1 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 14 Feb 2022 13:20:17 -0500 Subject: [PATCH 3/4] test(utils): Add regression test for console functionality --- .../suites/public-api/init/console/test.ts | 23 +++++++++++++++++++ .../suites/public-api/init/init.js | 7 ++++++ .../suites/public-api/init/template.hbs | 11 +++++++++ 3 files changed, 41 insertions(+) create mode 100644 packages/integration-tests/suites/public-api/init/console/test.ts create mode 100644 packages/integration-tests/suites/public-api/init/init.js create mode 100644 packages/integration-tests/suites/public-api/init/template.hbs diff --git a/packages/integration-tests/suites/public-api/init/console/test.ts b/packages/integration-tests/suites/public-api/init/console/test.ts new file mode 100644 index 000000000000..a70e74b3bcd9 --- /dev/null +++ b/packages/integration-tests/suites/public-api/init/console/test.ts @@ -0,0 +1,23 @@ +/* eslint-disable no-console */ +import { ConsoleMessage, expect } from '@playwright/test'; + +import { sentryTest } from '../../../../utils/fixtures'; + +// Regression test against https://github.com/getsentry/sentry-javascript/issues/4558 +// See PR which introduced problem https://github.com/getsentry/sentry-javascript/pull/4533 +sentryTest('should not overwrite console functionality', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + + // https://playwright.dev/docs/api/class-page#page-event-console + page.on('console', (msg: ConsoleMessage) => { + expect(msg.text()).toEqual(`hello world ${msg.type()}`); + }); + + await page.goto(url); + + await page.evaluate(() => console.log('hello', 'world', 'log')); + + await page.evaluate(() => console.warn('hello', 'world', 'warning')); + + await page.evaluate(() => console.debug('hello', 'world', 'debug')); +}); diff --git a/packages/integration-tests/suites/public-api/init/init.js b/packages/integration-tests/suites/public-api/init/init.js new file mode 100644 index 000000000000..d8c94f36fdd0 --- /dev/null +++ b/packages/integration-tests/suites/public-api/init/init.js @@ -0,0 +1,7 @@ +import * as Sentry from '@sentry/browser'; + +window.Sentry = Sentry; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', +}); diff --git a/packages/integration-tests/suites/public-api/init/template.hbs b/packages/integration-tests/suites/public-api/init/template.hbs new file mode 100644 index 000000000000..a28a09b7b485 --- /dev/null +++ b/packages/integration-tests/suites/public-api/init/template.hbs @@ -0,0 +1,11 @@ + + + + + + + + + + + From a3b37d8df9c8e6d86954d754d3c0d21a9333915b Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 14 Feb 2022 14:03:47 -0500 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Katie Byers --- .../integration-tests/suites/public-api/init/console/test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/integration-tests/suites/public-api/init/console/test.ts b/packages/integration-tests/suites/public-api/init/console/test.ts index a70e74b3bcd9..1f71332533c8 100644 --- a/packages/integration-tests/suites/public-api/init/console/test.ts +++ b/packages/integration-tests/suites/public-api/init/console/test.ts @@ -4,8 +4,7 @@ import { ConsoleMessage, expect } from '@playwright/test'; import { sentryTest } from '../../../../utils/fixtures'; // Regression test against https://github.com/getsentry/sentry-javascript/issues/4558 -// See PR which introduced problem https://github.com/getsentry/sentry-javascript/pull/4533 -sentryTest('should not overwrite console functionality', async ({ getLocalTestPath, page }) => { +sentryTest('should not change console output', async ({ getLocalTestPath, page }) => { const url = await getLocalTestPath({ testDir: __dirname }); // https://playwright.dev/docs/api/class-page#page-event-console