-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (66 loc) · 2.89 KB
/
Copy pathindex.js
File metadata and controls
82 lines (66 loc) · 2.89 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
const path = require('path');
const fs = require('fs');
const minimist = require('minimist');
const { webkit, devices } = require('playwright');
const { auditManifest } = require('./src/cli/modules/manifestAuditor');
const { injectServiceWorkerLogger } = require('./src/cli/modules/swLogger');
const { setupOfflineToggle } = require('./src/cli/modules/offlineManager');
const { injectSafeAreaOverlay } = require('./src/cli/modules/safeAreaInjector');
// Set custom browser path if running in this environment
const localBrowsersPath = path.join(__dirname, 'browsers');
if (fs.existsSync(localBrowsersPath)) {
process.env.PLAYWRIGHT_BROWSERS_PATH = localBrowsersPath;
}
(async () => {
const chalk = (await import('chalk')).default;
const args = minimist(process.argv.slice(2));
let targetUrl = args.url || args._[0] || 'http://localhost:3000';
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
targetUrl = 'http://' + targetUrl;
}
console.log(chalk.bold.cyan('\n📱 iOS PWA Auditor & Simulator'));
console.log(chalk.gray('-----------------------------------'));
console.log(chalk.blue(`Target URL: `) + chalk.underline(targetUrl));
try {
console.log(chalk.yellow('⏳ Launching WebKit...'));
const browser = await webkit.launch({ headless: false });
// PWA Context (Standalone Mode)
const context = await browser.newContext({
...devices['iPhone 13 Pro'],
viewport: { width: 390, height: 844 }, // Full screen dimensions
deviceScaleFactor: 3,
isMobile: true,
hasTouch: true,
locale: 'en-US',
timezoneId: 'America/New_York',
});
// 1. Service Worker Logger
await injectServiceWorkerLogger(context, chalk);
// 2. Offline Toggle
await setupOfflineToggle(context, chalk);
// 3. Safe Area Overlay
await injectSafeAreaOverlay(context);
const page = await context.newPage();
console.log(chalk.yellow(`🚀 Navigating to ${targetUrl}...`));
// Navigate
await page.goto(targetUrl).catch(e => {
console.error(chalk.red(`❌ Navigation failed: ${e.message}`));
});
// 4. Manifest Audit (After navigation so we can find the link tag)
await auditManifest(page, chalk);
console.log(chalk.green('\n✨ Simulation running!'));
console.log(chalk.gray(' • Click the green "Go Offline" button in the app to test offline mode.'));
console.log(chalk.gray(' • Click the red Safe Area overlays to toggle them.'));
console.log(chalk.gray(' • Service Worker logs will appear here in the console.'));
console.log(chalk.gray('Press Ctrl+C to exit.'));
process.on('SIGINT', async () => {
console.log(chalk.yellow('\nClosing browser...'));
await browser.close();
process.exit();
});
} catch (error) {
console.error(chalk.red('\n🔥 FATAL ERROR:'));
console.error(chalk.red(` ${error.message}`));
process.exit(1);
}
})();