docs: document idleDetector
permissions (#39180)
doc: document idleDetector permissions
This commit is contained in:
parent
cd408a826c
commit
1231f0a734
3 changed files with 118 additions and 9 deletions
|
@ -891,18 +891,19 @@ win.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||||
* `permission` string - The type of requested permission.
|
* `permission` string - The type of requested permission.
|
||||||
* `clipboard-read` - Request access to read from the clipboard.
|
* `clipboard-read` - Request access to read from the clipboard.
|
||||||
* `clipboard-sanitized-write` - Request access to write to the clipboard.
|
* `clipboard-sanitized-write` - Request access to write to the clipboard.
|
||||||
|
* `display-capture` - Request access to capture the screen via the [Screen Capture API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API).
|
||||||
|
* `fullscreen` - Request control of the app's fullscreen state via the [Fullscreen API](https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API).
|
||||||
|
* `geolocation` - Request access to the user's location via the [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API)
|
||||||
|
* `idle-detection` - Request access to the user's idle state via the [IdleDetector API](https://developer.mozilla.org/en-US/docs/Web/API/IdleDetector).
|
||||||
* `media` - Request access to media devices such as camera, microphone and speakers.
|
* `media` - Request access to media devices such as camera, microphone and speakers.
|
||||||
* `display-capture` - Request access to capture the screen.
|
|
||||||
* `mediaKeySystem` - Request access to DRM protected content.
|
* `mediaKeySystem` - Request access to DRM protected content.
|
||||||
* `geolocation` - Request access to user's current location.
|
* `midi` - Request MIDI access in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
|
||||||
* `notifications` - Request notification creation and the ability to display them in the user's system tray.
|
* `midiSysex` - Request the use of system exclusive messages in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
|
||||||
* `midi` - Request MIDI access in the `webmidi` API.
|
* `notifications` - Request notification creation and the ability to display them in the user's system tray using the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/notification)
|
||||||
* `midiSysex` - Request the use of system exclusive messages in the `webmidi` API.
|
* `pointerLock` - Request to directly interpret mouse movements as an input method via the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API). These requests always appear to originate from the main frame.
|
||||||
* `pointerLock` - Request to directly interpret mouse movements as an input method. Click [here](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API) to know more. These requests always appear to originate from the main frame.
|
|
||||||
* `fullscreen` - Request for the app to enter fullscreen mode.
|
|
||||||
* `openExternal` - Request to open links in external applications.
|
* `openExternal` - Request to open links in external applications.
|
||||||
* `window-management` - Request access to enumerate screens using the [`getScreenDetails`](https://developer.chrome.com/en/articles/multi-screen-window-placement/) API.
|
* `window-management` - Request access to enumerate screens using the [`getScreenDetails`](https://developer.chrome.com/en/articles/multi-screen-window-placement/) API.
|
||||||
* `unknown` - An unrecognized permission request
|
* `unknown` - An unrecognized permission request.
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
* `permissionGranted` boolean - Allow or deny the permission.
|
* `permissionGranted` boolean - Allow or deny the permission.
|
||||||
* `details` Object - Some properties are only available on certain permission types.
|
* `details` Object - Some properties are only available on certain permission types.
|
||||||
|
@ -934,7 +935,22 @@ session.fromPartition('some-partition').setPermissionRequestHandler((webContents
|
||||||
|
|
||||||
* `handler` Function\<boolean> | null
|
* `handler` Function\<boolean> | null
|
||||||
* `webContents` ([WebContents](web-contents.md) | null) - WebContents checking the permission. Please note that if the request comes from a subframe you should use `requestingUrl` to check the request origin. All cross origin sub frames making permission checks will pass a `null` webContents to this handler, while certain other permission checks such as `notifications` checks will always pass `null`. You should use `embeddingOrigin` and `requestingOrigin` to determine what origin the owning frame and the requesting frame are on respectively.
|
* `webContents` ([WebContents](web-contents.md) | null) - WebContents checking the permission. Please note that if the request comes from a subframe you should use `requestingUrl` to check the request origin. All cross origin sub frames making permission checks will pass a `null` webContents to this handler, while certain other permission checks such as `notifications` checks will always pass `null`. You should use `embeddingOrigin` and `requestingOrigin` to determine what origin the owning frame and the requesting frame are on respectively.
|
||||||
* `permission` string - Type of permission check. Valid values are `midiSysex`, `notifications`, `geolocation`, `media`,`mediaKeySystem`,`midi`, `pointerLock`, `fullscreen`, `openExternal`, `hid`, `serial`, or `usb`.
|
* `permission` string - Type of permission check.
|
||||||
|
* `clipboard-read` - Request access to read from the clipboard.
|
||||||
|
* `clipboard-sanitized-write` - Request access to write to the clipboard.
|
||||||
|
* `geolocation` - Access the user's geolocation data via the [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API)
|
||||||
|
* `fullscreen` - Control of the app's fullscreen state via the [Fullscreen API](https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API).
|
||||||
|
* `hid` - Access the HID protocol to manipulate HID devices via the [WebHID API](https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API).
|
||||||
|
* `idle-detection` - Access the user's idle state via the [IdleDetector API](https://developer.mozilla.org/en-US/docs/Web/API/IdleDetector).
|
||||||
|
* `media` - Access to media devices such as camera, microphone and speakers.
|
||||||
|
* `mediaKeySystem` - Access to DRM protected content.
|
||||||
|
* `midi` - Enable MIDI access in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
|
||||||
|
* `midiSysex` - Use system exclusive messages in the [Web MIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API).
|
||||||
|
* `notifications` - Configure and display desktop notifications to the user with the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/notification).
|
||||||
|
* `openExternal` - Open links in external applications.
|
||||||
|
* `pointerLock` - Directly interpret mouse movements as an input method via the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API). These requests always appear to originate from the main frame.
|
||||||
|
* `serial` - Read from and write to serial devices with the [Web Serial API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API).
|
||||||
|
* `usb` - Expose non-standard Universal Serial Bus (USB) compatible devices services to the web with the [WebUSB API](https://developer.mozilla.org/en-US/docs/Web/API/WebUSB_API).
|
||||||
* `requestingOrigin` string - The origin URL of the permission check
|
* `requestingOrigin` string - The origin URL of the permission check
|
||||||
* `details` Object - Some properties are only available on certain permission types.
|
* `details` Object - Some properties are only available on certain permission types.
|
||||||
* `embeddingOrigin` string (optional) - The origin of the frame embedding the frame that made the permission check. Only set for cross-origin sub frames making permission checks.
|
* `embeddingOrigin` string (optional) - The origin of the frame embedding the frame that made the permission check. Only set for cross-origin sub frames making permission checks.
|
||||||
|
|
|
@ -1326,6 +1326,94 @@ describe('chromium features', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('IdleDetection', () => {
|
||||||
|
afterEach(closeAllWindows);
|
||||||
|
afterEach(() => {
|
||||||
|
session.defaultSession.setPermissionCheckHandler(null);
|
||||||
|
session.defaultSession.setPermissionRequestHandler(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can grant a permission request', async () => {
|
||||||
|
session.defaultSession.setPermissionRequestHandler(
|
||||||
|
(_wc, permission, callback) => {
|
||||||
|
callback(permission === 'idle-detection');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
|
||||||
|
const permission = await w.webContents.executeJavaScript(`
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const button = document.getElementById('button');
|
||||||
|
button.addEventListener("click", async () => {
|
||||||
|
const permission = await IdleDetector.requestPermission();
|
||||||
|
resolve(permission);
|
||||||
|
});
|
||||||
|
button.click();
|
||||||
|
});
|
||||||
|
`, true);
|
||||||
|
|
||||||
|
expect(permission).to.eq('granted');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can deny a permission request', async () => {
|
||||||
|
session.defaultSession.setPermissionRequestHandler(
|
||||||
|
(_wc, permission, callback) => {
|
||||||
|
callback(permission !== 'idle-detection');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
|
||||||
|
const permission = await w.webContents.executeJavaScript(`
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const button = document.getElementById('button');
|
||||||
|
button.addEventListener("click", async () => {
|
||||||
|
const permission = await IdleDetector.requestPermission();
|
||||||
|
resolve(permission);
|
||||||
|
});
|
||||||
|
button.click();
|
||||||
|
});
|
||||||
|
`, true);
|
||||||
|
|
||||||
|
expect(permission).to.eq('denied');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can allow the IdleDetector to start', async () => {
|
||||||
|
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
|
||||||
|
return permission === 'idle-detection';
|
||||||
|
});
|
||||||
|
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||||
|
const result = await w.webContents.executeJavaScript(`
|
||||||
|
const detector = new IdleDetector({ threshold: 60000 });
|
||||||
|
detector.start().then(() => {
|
||||||
|
return 'success';
|
||||||
|
}).catch(e => e.message);
|
||||||
|
`, true);
|
||||||
|
|
||||||
|
expect(result).to.eq('success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can prevent the IdleDetector from starting', async () => {
|
||||||
|
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
|
||||||
|
return permission !== 'idle-detection';
|
||||||
|
});
|
||||||
|
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||||
|
const result = await w.webContents.executeJavaScript(`
|
||||||
|
const detector = new IdleDetector({ threshold: 60000 });
|
||||||
|
detector.start().then(() => {
|
||||||
|
console.log('success')
|
||||||
|
}).catch(e => e.message);
|
||||||
|
`, true);
|
||||||
|
|
||||||
|
expect(result).to.eq('Idle detection permission denied');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('navigator.mediaDevices', () => {
|
describe('navigator.mediaDevices', () => {
|
||||||
afterEach(closeAllWindows);
|
afterEach(closeAllWindows);
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|
5
spec/fixtures/pages/button.html
vendored
Normal file
5
spec/fixtures/pages/button.html
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<button id="button">CLICK</button>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue