Sharesheet from WebView does not recognize PDF

Hello everyone! I am new to this forum but was hoping somebody may be able to help.

I have a simple script that uses a WebView to open a webpage to a news database and use several calls to evaluateJavaScript to login, navigate through a few links, and selects a link to a PDF of an article.

For some reason when I then tried to load this url directly with await wv.loadURL(pdf_url) it would always give me the error: Error: URL is invalid: ... Due to some form of a login token / cookies issue, I am also unable to call as well.

So, to get around this, instead of having the javascript just return this url in the last step I change the window location: window.location.href = pdf_url and then make a call to await wv.present()

Everything works and in the popup window I see the PDF, however when I click on the share button the only option that comes up is SHARE URL. It does not recognize that there is a file being displayed. So, I cannot save the PDF from share sheet as I could in do if I were to go through all the steps by hand in Safari.

I am wondering if anybody has some suggested work arounds or advice!

I am happy to share the full code if anybody would like however it will not run on anybody’s machine since the url can only be accessed from my university network.

I would really appreciate any help as I have been stuck on this for quite awhile! Thank you :smile: