Web Browser bug (macOS)


We’ve been building some new features using the WebBrowserComponent. Part of this is a local html page accessed via a file:// reference. What we noticed was that because of the way the URL is opened in this case any query strings (parameters) were being stripped. The way we fixed it was like this:

if (trimmed.startsWithIgnoreCase ("file:"))
    auto file = URL (url).getLocalFile();
    const URL localURL (url);

    auto file = localURL.getLocalFile();

    if (NSURL* nsUrl = [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())])
        const auto parameterNames = localURL.getParameterNames();
        const auto parameterValues = localURL.getParameterValues();
        if (parameterNames.size() != 0 &&
            parameterValues.size() != 0 &&
            parameterNames.size() == parameterValues.size())
            NSURLComponents* components = [[NSURLComponents alloc] initWithURL:nsUrl resolvingAgainstBaseURL:NO];
            NSMutableArray* queryItems = [components.queryItems mutableCopy];
            if (!queryItems)
                queryItems = [[NSMutableArray alloc] init];

            for (auto parameter = 0; parameter < parameterNames.size(); ++parameter)
                [queryItems addObject:[NSURLQueryItem queryItemWithName: juceStringToNS(parameterNames[parameter])
                                                                    value: juceStringToNS(parameterValues[parameter])]];

            components.queryItems = queryItems;
            nsUrl = components.URL;

        [webView loadFileURL: nsUrl allowingReadAccessToURL: nsUrl];

Ive included it as a patch… 0001-Append-query-string-to-local-file-urls.patch (2.3 KB)