Repository navigation
Expand file tree
/
Copy pathscreenshot_game.js
More file actions
98 lines (85 loc) · 3.06 KB
/
Copy pathscreenshot_game.js
File metadata and controls
98 lines (85 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { chromium } = require('playwright');
const fs = require('fs');
(async () => {
const envContent = fs.readFileSync('.dev.vars', 'utf-8');
const match = envContent.match(/WORKOS_API_KEY=(.+)/);
const key = match[1].trim();
const { SignJWT } = await import('jose');
const jwt = await new SignJWT({ sub: 'test-user-id' })
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('1h')
.sign(new TextEncoder().encode(key));
const browser = await chromium.launch({ headless: true, args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'] });
const ctx = await browser.newContext({ viewport: { width: 1280, height: 720 } });
await ctx.addCookies([{
name: 'session', value: jwt,
domain: 'robocode.rahejaom.workers.dev', path: '/',
httpOnly: true, secure: true,
}]);
const page = await ctx.newPage();
page.on('pageerror', err => console.log('PAGE_ERR:', err.message));
await page.goto('https://robocode.rahejaom.workers.dev/game', { waitUntil: 'load', timeout: 30000 });
await page.waitForTimeout(5000);
// Dismiss "How to play" modal by finding the Got it! button
await page.evaluate(() => {
const buttons = document.querySelectorAll('button');
for (const btn of buttons) {
if (btn.textContent.includes('Got it')) {
btn.click();
return true;
}
}
return false;
});
console.log('Dismissed How to play');
await page.waitForTimeout(1000);
// Close any other modals (Guilds etc) by clicking X buttons
await page.evaluate(() => {
const closeButtons = document.querySelectorAll('button');
for (const btn of closeButtons) {
if (btn.textContent.includes('\u00d7') || btn.getAttribute('aria-label')?.includes('close')) {
btn.click();
}
}
});
// Also press Escape to close any remaining modals
await page.keyboard.press('Escape');
await page.waitForTimeout(1000);
await page.screenshot({ path: '/tmp/g1.png' });
console.log('S1: spawn');
// Walk north
await page.keyboard.down('w');
await page.waitForTimeout(3000);
await page.keyboard.up('w');
await page.screenshot({ path: '/tmp/g2.png' });
console.log('S2: north');
// More north
await page.keyboard.down('w');
await page.waitForTimeout(3000);
await page.keyboard.up('w');
await page.screenshot({ path: '/tmp/g3.png' });
console.log('S3: more north');
// East
await page.keyboard.down('d');
await page.waitForTimeout(4000);
await page.keyboard.up('d');
await page.screenshot({ path: '/tmp/g4.png' });
console.log('S4: east');
// Far east
await page.keyboard.down('d');
await page.waitForTimeout(4000);
await page.keyboard.up('d');
await page.screenshot({ path: '/tmp/g5.png' });
console.log('S5: far east');
// Northwest
await page.keyboard.down('a');
await page.keyboard.down('w');
await page.waitForTimeout(5000);
await page.keyboard.up('a');
await page.keyboard.up('w');
await page.screenshot({ path: '/tmp/g6.png' });
console.log('S6: northwest');
await browser.close();
console.log('Done');
})().catch(e => console.error(e));