Skip to content

Commit bc1d11c

Browse files
authored
feat: support passing additional permissions to the iframe (#911)
1 parent 75a814f commit bc1d11c

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

docs/content/2.module/0.guide.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ nuxt.hook('devtools:customTabs', (tabs) => {
5959
})
6060
```
6161

62+
### Iframe Permissions
63+
64+
By default, iframes have `clipboard-write` and `clipboard-read` permissions enabled. You can add additional permissions using the `permissions` option:
65+
66+
```ts
67+
const view: ModuleIframeView = {
68+
type: 'iframe',
69+
src: '/url-to-your-module-view',
70+
// Additional permissions to allow in the iframe
71+
permissions: ['camera', 'microphone', 'geolocation'],
72+
}
73+
```
74+
75+
These permissions will be merged with the default ones and set on the iframe's `allow` attribute.
76+
6277
Learn more about [DevTools Utility Kit](/module/utils-kit).
6378

6479
## Lazy Service Launching

docs/content/2.module/1.utils-kit.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ addCustomTab(() => ({
3939
}))
4040
```
4141

42+
The iframe view supports the following options:
43+
44+
- `src`: URL of the iframe
45+
- `persistent`: Whether to persist the iframe instance when switching tabs (default: `true`)
46+
- `permissions`: Additional permissions to allow in the iframe (merged with default `clipboard-write` and `clipboard-read`)
47+
48+
```ts
49+
const view: ModuleIframeView = {
50+
type: 'iframe',
51+
src: '/url-to-your-module-view',
52+
persistent: true,
53+
permissions: ['camera', 'microphone'],
54+
}
55+
```
56+
4257
### `refreshCustomTabs()`
4358

4459
A shorthand for call hook `devtools:customTabs:refresh`. It will refresh all custom tabs.

packages/devtools-kit/src/_types/custom-tabs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export interface ModuleIframeView {
6868
* @default true
6969
*/
7070
persistent?: boolean
71+
/**
72+
* Additional permissions to allow in the iframe
73+
* These will be merged with the default permissions (clipboard-write, clipboard-read)
74+
*
75+
* @example ['camera', 'microphone', 'geolocation']
76+
*/
77+
permissions?: string[]
7178
}
7279

7380
export interface ModuleVNodeView {

packages/devtools/client/components/IframeView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const box = reactive(useElementBounding(anchor))
2323
onMounted(() => {
2424
const view = props.tab.view as ModuleIframeView
2525
const isPersistent = view.persistent !== false
26-
const allowedPermissions = ['clipboard-write', 'clipboard-read']
26+
const allowedPermissions = ['clipboard-write', 'clipboard-read', ...(view.permissions || [])]
2727
2828
if (iframeCacheMap.get(key.value) && isPersistent) {
2929
iframeEl.value = iframeCacheMap.get(key.value)!

0 commit comments

Comments
 (0)