I got a number of Google Apps Script Web Apps. They all use image files, Materialize.min.css, and materilize.min.js sitting on other servers. I wanted to move all those files under my control onto my google drive. I've been successful with the image files and the materialize.min.css, but for some reason the maerialize.min.js
is causing problems.
For the CSS files I used to use
link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" /
I now use
link rel="stylesheet"
href="https://drive.google.com/uc?export=view&id=1UQ_tm8_bUOXWj1GdzS8JmkehwVf5sW3A" />
And it all works well.
For the JS files: I used to use
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <?!= include("page-js");?>"
I've tried
<script src="https://drive.google.com/uc?export=download&id=1SkfRcC1jQwNLRVEUPgjQHSUkEFdg1BND"></script> <?!= include("page-js");?>"
Also tried export=view
I get the runtime error
userCodeAppPanel:47 Uncaught ReferenceError: M is not defined at HTMLDocument.
So it seems to read the file, but doesn't seem to load the js????
I'm not sure how to fix it. Any suggestions would be appreciated.
CodePudding user response:
This is because Google Drive recognizes that this is a js
file and doesn't allow a direct link, but redirects to a warning page which requires a confirmation by the end user(using a query string confirm=****
as described here). Unfortunately, I don't think it's possible to retrieve this confirmation token client side due to CORB.
Workaround:
Create a simple web app function
doGet()
Return data using ContentService
Use the published web app url in
script src