4

I would like to build a hybrid app which targets a single website. The app would allow for the automation of certain tasks by injecting java script into the webpage. I do not have any influence over the development of the webpage.

In the automation steps I need to upload a file (eg Word docx, Outlook msg or PDF) to the webpage. In my Chrome extension, for example I turn the file into base64 and send it as a string (in parts) to the page. On the page I have some java script that converts the Base64 to a blob. Such a method would not be my first choice for WebView2, however can PostWebMessageAsString handle a Base64 string with a few MB in size? What would be the MAX size it could handle?

How else can I get a file from the local system into the webpage? Is there a way to even use local file system paths? Or is there a possibility (I believe CEFSharp has this) to set up a custom Schema ( SchemeHandler) to add resources?

Also I would like to add a JS file to the webpage containing a lot of the functions I later intend to call. This maybe a similar question to the one I have above, but how can I upload this file? Or could I add a reference to a JS file with a local file system path in the SCRIPT tag?

darbid
  • 2,545
  • 23
  • 55
  • You can see this document on interacting with local content: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/working-with-local-content?tabs=dotnetcsharp – David Risney Jun 08 '23 at 18:32

1 Answers1

0

Not sure if this is the best way to do this or not, but since the answer to this one is largley the same process as the previous question I have just answered, I would like to point your attention to that answer:

Hide or modify the toolbar of Webview2 when viewing pdf

That solves your "running Javascript" part of the question.

As for "PostWebMessageAsString" yes, it should be able to handle the maximum size of a regular string.

I have not read anywhere that there are any limits on the call, and so far I have serialized some large object collections C# side to json, and sent them using the postmessage call without any difficulty.

You DO NEED to have some JS code running in your webview2 session that intercepts the post message event, the best way to do that is to use the methods I outline in my other answer to insert some JS code into your webview prior to running/loading the page.

shawty
  • 5,729
  • 2
  • 37
  • 71