Skip to content

Commit

Permalink
fix: make push work with strict CSP (#20342)
Browse files Browse the repository at this point in the history
  • Loading branch information
tepi authored and vaadin-bot committed Oct 29, 2024
1 parent f76b212 commit 0657e15
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions flow-client/src/main/frontend/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ export class Flow {
private async flowInit(): Promise<AppInitResponse> {
// Do not start flow twice
if (!this.isFlowClientLoaded()) {
$wnd.Vaadin.Flow.nonce = this.findNonce();

// show flow progress indicator
this.loadingStarted();

Expand Down Expand Up @@ -349,15 +351,35 @@ export class Flow {
script.onload = () => resolve();
script.onerror = reject;
script.src = url;
const nonce = $wnd.Vaadin.Flow.nonce;

Check warning on line 354 in flow-client/src/main/frontend/Flow.ts

View workflow job for this annotation

GitHub Actions / build

Use object destructuring
if (nonce !== undefined) {
script.setAttribute('nonce', nonce);
}
document.body.appendChild(script);
});
}

private findNonce(): string | undefined {
let nonce;
const scriptTags = document.head.getElementsByTagName('script');
for (const scriptTag of scriptTags) {
if (scriptTag.nonce) {
nonce = scriptTag.nonce;
break;
}
}
return nonce;
}

private injectAppIdScript(appId: string) {
const appIdWithoutHashCode = appId.substring(0, appId.lastIndexOf('-'));
const scriptAppId = document.createElement('script');
scriptAppId.type = 'module';
scriptAppId.setAttribute('data-app-id', appIdWithoutHashCode);
const nonce = $wnd.Vaadin.Flow.nonce;

Check warning on line 379 in flow-client/src/main/frontend/Flow.ts

View workflow job for this annotation

GitHub Actions / build

Use object destructuring
if (nonce !== undefined) {
scriptAppId.setAttribute('nonce', nonce);
}
document.body.append(scriptAppId);
}

Expand Down

0 comments on commit 0657e15

Please sign in to comment.