How to use _onTargetCrashed 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.

simulate_page_crash.js

Source: simulate_page_crash.js Github

copy
1const puppeteer = require('puppeteer');
2const fs = require('fs');
3
4class Server {
5    async setup() {
6        if (!this.browser) {
7            this.browser = await puppeteer.launch({ args : ['--no-sandbox'] });
8        }
9    }
10
11    async runner() {
12        await this.setup();
13
14        const me = this;
15
16        this.browser.on('disconnected', function () {
17            const a = me;
18
19            console.log('pup exit code:' + this.process().exitCode);
20        });
21
22        const page = await this.browser.newPage();
23
24        const a = 1, b = 2;
25
26        await page.setViewport({
27            width             : 50000,
28            height            : 50000,
29            deviceScaleFactor : 8
30        });
31
32        // page._onTargetCrashed(new Error('sim'));
33
34        await page.goto('https://www.google.com', { waitUntil : 'networkidle0' });
35        // await page.setContent('<html lang="en"><head><title>test</title><rel type="stylesheet" href="htt"></rel></head><body></body></html>', { timeout : 1, waitUntil : 'load' });
36
37        // await page.close();
38
39        await page.goto('http://www.bing.com', { waitUntil : 'networkidle0' });
40
41        console.log('closing browser');
42
43        await this.browser.close();
44
45        console.log('browser closed');
46    }
47
48    async export() {
49        try {
50            await this.runner();
51        }
52        catch (e) {
53            console.log('Page crash');
54
55            console.error(e.stack);
56
57            await this.browser.close();
58
59            // await this.runner();
60
61            throw e;
62        }
63    }
64}
65
66const srv = new Server();
67
68srv.export()
69    .then(() => process.exit())
70    .catch(e => {
71        console.log(e);
72
73        process.exit(1);
74    });
75
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)