|
| 1 | +import { wait } from '@root/utils' |
| 2 | +import { expect, test } from './fixtures' |
| 3 | +import { evaluate } from './utils' |
| 4 | + |
| 5 | +const url = 'https://bot-detector.rebrowser.net/' |
| 6 | + |
| 7 | +test('bot detector', async ({ page }) => { |
| 8 | + await page.goto(url) |
| 9 | + |
| 10 | + await page.evaluate(() => window.dummyFn()) |
| 11 | + |
| 12 | + // exposeFunctionLeak |
| 13 | + await page.exposeFunction('exposedFn', () => { |
| 14 | + console.log('exposedFn call') |
| 15 | + }) |
| 16 | + |
| 17 | + // sourceUrlLeak |
| 18 | + await page.evaluate(() => document.getElementById('detections-json')) |
| 19 | + |
| 20 | + /* |
| 21 | + playwright - there is no way to explicitly evaluate script in an isolated context |
| 22 | + follow rebrowser-patches on github for the fix |
| 23 | + */ |
| 24 | + await page.evaluate(() => document.getElementsByClassName('div')) |
| 25 | + |
| 26 | + await wait(3000) |
| 27 | + const { isBot, botStatus } = await evaluate(page, () => { |
| 28 | + const els = Array.from( |
| 29 | + document.querySelectorAll('tbody>tr>td:nth-child(1)'), |
| 30 | + ) as HTMLElement[] |
| 31 | + |
| 32 | + let botStatus = [] as string[], |
| 33 | + isBot = false |
| 34 | + for (const el of els) { |
| 35 | + if (el.innerText.startsWith('🔴')) { |
| 36 | + botStatus.push(el.innerText) |
| 37 | + isBot = true |
| 38 | + } |
| 39 | + } |
| 40 | + return { isBot, botStatus } |
| 41 | + }) |
| 42 | + |
| 43 | + if (!isBot) { |
| 44 | + console.error('🔴 botStatus', botStatus) |
| 45 | + } |
| 46 | + await expect(isBot).toBe(false) |
| 47 | +}) |
0 commit comments