electron#HeadersReceivedResponse TypeScript Examples

The following examples show how to use electron#HeadersReceivedResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: contentSecurityPolicy.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupContentSecurityPolicy (_: string): void {
  session.defaultSession.webRequest.onHeadersReceived((details, respond: (response: HeadersReceivedResponse) => void) => {
    respond({
      responseHeaders: {
        ...details.responseHeaders,
        'Content-Security-Policy': [
          "default-src 'self';" +
          " style-src-elem 'self' https://fonts.googleapis.com/css 'unsafe-inline';" +
          " font-src data: 'self' https://fonts.gstatic.com;" +
          " style-src 'unsafe-inline';" +
          " connect-src 'self' wss: ws:;" +
          " img-src 'self' data:;" +
          // react-qr-reader uses an embedded blob
          " worker-src 'self' blob: filesystem:;" +
          // unsafe-eval is needed for the WASM content - same as the extension
          // script hashes here are for the window.top script (not technically needed)
          " script-src 'self' 'unsafe-eval' 'sha256-02/ejyoV/iwRdJ4NAsxjzF6WVUtLMPM6Nv96EbAm6u8=' 'sha256-wW/WsLudCDaPo/ibpeK0KslHqYpCzcAKNFxFBXwCHJg='"
        ]
      }
    });
  });
}
Example #2
Source File: cors-skip.ts    From dev-manager-desktop with Apache License 2.0 5 votes vote down vote up
function AllowCORSHandler(details: OnHeadersReceivedListenerDetails, callback: (resp: HeadersReceivedResponse) => void): void {
  details.responseHeaders['access-control-allow-origin'] = ['*'];
  callback({
    cancel: false,
    responseHeaders: {...details.responseHeaders}
  });
}