Improve microphone permission UX: add Dev Log, re-request flow, active Voice Input highlighting, and Puppeteer permission-check script
This commit is contained in:
62
scripts/permission-check.js
Normal file
62
scripts/permission-check.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
async function run() {
|
||||
const url = process.argv[2] || 'http://localhost:3000';
|
||||
console.log('Checking permissions for', url);
|
||||
|
||||
const browser = await puppeteer.launch({ headless: true });
|
||||
const context = browser.defaultBrowserContext();
|
||||
const page = await browser.newPage();
|
||||
|
||||
try {
|
||||
await page.goto(url, { waitUntil: 'networkidle2', timeout: 10000 });
|
||||
|
||||
const getState = async () => {
|
||||
return await page.evaluate(async () => {
|
||||
if (!navigator.permissions) return null;
|
||||
try {
|
||||
const s = await navigator.permissions.query({ name: 'microphone' });
|
||||
return s.state;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const before = await getState();
|
||||
console.log('permission state before override:', before);
|
||||
|
||||
// Programmatically grant microphone permission for the origin
|
||||
try {
|
||||
await context.overridePermissions(url, ['microphone']);
|
||||
console.log('overridePermissions: granted microphone');
|
||||
} catch (e) {
|
||||
console.warn('overridePermissions failed:', e.message || e);
|
||||
}
|
||||
|
||||
await page.reload({ waitUntil: 'networkidle2', timeout: 10000 });
|
||||
const after = await getState();
|
||||
console.log('permission state after override/reload:', after);
|
||||
|
||||
// Try calling the app's check function if present
|
||||
const appLog = await page.evaluate(() => {
|
||||
try {
|
||||
if (typeof checkMicrophonePermission === 'function') {
|
||||
checkMicrophonePermission();
|
||||
return 'called checkMicrophonePermission()';
|
||||
}
|
||||
return 'no checkMicrophonePermission() function found';
|
||||
} catch (e) {
|
||||
return `error calling app fn: ${e.message || e}`;
|
||||
}
|
||||
});
|
||||
console.log(appLog);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Permission check failed:', err.message || err);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user