How to use disabledLog method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ConsolePatchingDev.js

Source: ConsolePatchingDev.js Github

copy
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10// Helpers to patch console.logs to avoid logging during side-effect free
11// replaying on render function. This currently only patches the object
12// lazily which won't cover if the log function was extracted eagerly.
13// We could also eagerly patch the method.
14
15let disabledDepth = 0;
16let prevLog;
17let prevInfo;
18let prevWarn;
19let prevError;
20
21function disabledLog() {}
22disabledLog.__reactDisabledLog = true;
23
24export function disableLogs(): void {
25  if (__DEV__) {
26    if (disabledDepth === 0) {
27      /* eslint-disable react-internal/no-production-logging */
28      prevLog = console.log;
29      prevInfo = console.info;
30      prevWarn = console.warn;
31      prevError = console.error;
32      // $FlowFixMe Flow thinks console is immutable.
33      console.log = console.info = console.warn = console.error = disabledLog;
34      /* eslint-enable react-internal/no-production-logging */
35    }
36    disabledDepth++;
37  }
38}
39
40export function reenableLogs(): void {
41  if (__DEV__) {
42    disabledDepth--;
43    if (disabledDepth === 0) {
44      /* eslint-disable react-internal/no-production-logging */
45      // $FlowFixMe Flow thinks console is immutable.
46      console.log = prevLog;
47      // $FlowFixMe Flow thinks console is immutable.
48      console.info = prevInfo;
49      // $FlowFixMe Flow thinks console is immutable.
50      console.warn = prevWarn;
51      // $FlowFixMe Flow thinks console is immutable.
52      console.error = prevError;
53      /* eslint-enable react-internal/no-production-logging */
54    }
55    if (disabledDepth < 0) {
56      console.error(
57        'disabledDepth fell below zero. ' +
58          'This is a bug in React. Please file an issue.',
59      );
60    }
61  }
62}
63
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)