Eilon / MauiHybridWebView

MIT License
203 stars 41 forks source link

Query parameters #2

Closed IeuanWalker closed 1 year ago

IeuanWalker commented 1 year ago

I'm currently building a PDF viewer using PDF.JS

Do to the URL having query string attached the PlatformOpenAppPackageFile doesnt ruturn a file -

Stream PlatformOpenAppPackageFile(string filename)
{
    filename = FileSystemUtils.NormalizePath(filename);

    try
    {
        return _handler.Context.Assets.Open(filename);
    }
    catch (Java.IO.FileNotFoundException)
    {
        return null;
    }
}

Example, viewer.html is the local PDF viewer, and file=*** is the PDF file to load -

Not quite sure how to get passed this issue.

Eilon commented 1 year ago

I created PR #6 to fix this. When (if 😄 ) that PR passes, you'll be able to download a ZIP that has a NuGet package that you can use in your app:

image

IeuanWalker commented 1 year ago

@Eilon Sorry only just got time to pick this back up.

It's still an issue.

Looks like the check you added is looking at a different URL than the one set on MainFile - image The URL set on MainFile is MainFile="pdfjs/web/viewer.html?file=../../Dissertation.pdf"

Here is a repo - https://github.com/IeuanWalker/Maui.PdfViewer

IeuanWalker commented 1 year ago

Also from your PR i couldn't see where you re-add the query parameters

Eilon commented 1 year ago

I'll take another look, thanks for checking!

Eilon commented 1 year ago

@IeuanWalker I have a new attempt to fix this issue: #17

This adds a new StartPath property that you can set to something like somefile.html?a=b&c=d. Please note that the MainFile property must be set to a specific file, which is what gets loaded if there is no other path specified (e.g. a request to /).

So in your case you could probably do something like this:

<hwv:HybridWebView ... MainFile="pdfjs/web/viewer.html" StartPath="?file=../../Dissertation.pdf" />

And that will load the view.html file as the default file, but the initial navigation will go to the particular query string with the PDF file specified.

IeuanWalker commented 1 year ago

Thanks @Eilon, will try and test it out now

Looks like its a different GitHub action than the last PR you built and no Artifacts were created

IeuanWalker commented 1 year ago

@Eilon just tried a bunch of stuff but getting this error logged in the console from the JS, which prevents the PDFViewer from working - "Uncaught ReferenceError: require is not defined", source: https://0.0.0.0/viewer.js (580)

Using the Standard Maui webview i dont get this error and the PDF loads fine.

I've done a bunch of search, but cant see why this error would appear as its still using the standard Android.Webkit.WebView

Eilon commented 1 year ago

Hi merged the PR, and the main build should produce artifacts in ~20min or so.

If you can create a repro project that uses the latest build and it still has the problem, please post that project and let me know so I can further investigate.

This control internally uses the same platform controls that the .NET MAUI WebView uses, but it configures it in a different way, so there could be some issues there that I will need to debug.