mhsohan / How-to-download-protected-view-only-files-from-google-drive-

47 stars 8 forks source link

This document requires 'TrustedScriptURL' assignment. #1

Open sowmiksudo opened 7 months ago

sowmiksudo commented 7 months ago

When I execute this snippet the console return the following error: This document requires 'TrustedScriptURL' assignment. (anonymous) @ VM426:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at <anonymous>:21:11

guohaoqiang commented 7 months ago

When I execute this snippet the console return the following error: This document requires 'TrustedScriptURL' assignment. (anonymous) @ VM426:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at <anonymous>:21:11

same here

Rajith-M commented 6 months ago

I think I found a fix, try this modified code: // Creating a Trusted Types policy const trustedTypesPolicy = window.trustedTypes.createPolicy('myTrustedTypesPolicy', { createScriptURL: (input) => input });

// Creating a TrustedScriptURL using the policy let jspdfSrc = trustedTypesPolicy.createScriptURL('https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js');

let jspdf = document.createElement("script");

jspdf.onload = function () { let pdf = new jsPDF(); let elements = document.getElementsByTagName("img"); for (let i in elements) { let img = elements[i]; if (!/^blob:/.test(img.src)) { continue; } let canvasElement = document.createElement('canvas'); let con = canvasElement.getContext("2d"); canvasElement.width = img.width; canvasElement.height = img.height; con.drawImage(img, 0, 0, img.width, img.height); let imgData = canvasElement.toDataURL("image/jpeg", 1.0); pdf.addImage(imgData, 'JPEG', 0, 0); pdf.addPage(); } pdf.save("download.pdf"); };

jspdf.src = jspdfSrc; // Assigning the TrustedScriptURL to src document.body.appendChild(jspdf);

babymonsterahyeon commented 5 months ago

when I type the modified code, it shows the following script, can you please help me????

Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js' because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-IwZdYZzL75p9Zk63LCVAfw' 'unsafe-inline'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

VM234:32 Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-inline' 'self' https://apis.google.com https://ssl.gstatic.com https://www.google.com https://www.googletagmanager.com https://www.gstatic.com https://www.google-analytics.com https://maps.googleapis.com https://ssl.google-analytics.com https://www.googleapis.com/appsmarket/v2/installedApps/". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Rajith-M commented 5 months ago

when I type the modified code, it shows the following script, can you please help me????

Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js' because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-IwZdYZzL75p9Zk63LCVAfw' 'unsafe-inline'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

VM234:32 Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-inline' 'self' https://apis.google.com https://ssl.gstatic.com https://www.google.com https://www.googletagmanager.com https://www.gstatic.com https://www.google-analytics.com https://maps.googleapis.com https://ssl.google-analytics.com https://www.googleapis.com/appsmarket/v2/installedApps/". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Try a different browser maybe? The CDN being blocked might have multiple reasons. Worst case try modifying the Content Security Policy manually.

DaoHa2410 commented 1 month ago

I think I found a fix, try this modified code: // Creating a Trusted Types policy const trustedTypesPolicy = window.trustedTypes.createPolicy('myTrustedTypesPolicy', { createScriptURL: (input) => input });

// Creating a TrustedScriptURL using the policy let jspdfSrc = trustedTypesPolicy.createScriptURL('https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js');

let jspdf = document.createElement("script");

jspdf.onload = function () { let pdf = new jsPDF(); let elements = document.getElementsByTagName("img"); for (let i in elements) { let img = elements[i]; if (!/^blob:/.test(img.src)) { continue; } let canvasElement = document.createElement('canvas'); let con = canvasElement.getContext("2d"); canvasElement.width = img.width; canvasElement.height = img.height; con.drawImage(img, 0, 0, img.width, img.height); let imgData = canvasElement.toDataURL("image/jpeg", 1.0); pdf.addImage(imgData, 'JPEG', 0, 0); pdf.addPage(); } pdf.save("download.pdf"); };

jspdf.src = jspdfSrc; // Assigning the TrustedScriptURL to src document.body.appendChild(jspdf);

can u pls help me fix code to download pptx file ? Thank you