Skip to content

Commit

Permalink
fix: support iframeProps option for CSP, fix Stackblitz
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 11, 2024
1 parent 988850f commit 0eb7a82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/devtools-kit/src/_types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface ModuleOptions {
*/
disableAuthorization?: boolean

/**
* Props for the iframe element, useful for environment with stricter CSP
*/
iframeProps?: Record<string, string | boolean>

/**
* Experimental features
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools/src/module-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {

await nuxt.callHook('devtools:before')

if (options.iframeProps)
nuxt.options.runtimeConfig.app.iframeProps = options.iframeProps

// Make unimport exposing more information, like the usage of each auto imported function
nuxt.options.imports.collectMeta = true

Expand Down
8 changes: 6 additions & 2 deletions packages/devtools/src/runtime/plugins/view/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ export async function setupDevToolsClient({
const initialUrl = CLIENT_PATH + state.value.route
try {
iframe = document.createElement('iframe')

// custom iframe props
Object.fromEntries(runtimeConfig.app.devtools?.iframeProps || {})
for (const [key, value] of Object.entries(runtimeConfig.app.devtools?.iframeProps || {}))
iframe.setAttribute(key, String(value))

iframe.id = 'nuxt-devtools-iframe'
iframe.allow = 'cross-origin-isolated'
iframe.setAttribute('credentialless', 'true')
iframe.src = initialUrl
iframe.onload = async () => {
try {
Expand Down

0 comments on commit 0eb7a82

Please sign in to comment.