Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use set_html with string longer than 1572834 characters on Windows #1104

Open
rcorre opened this issue Apr 11, 2024 · 4 comments
Open

Comments

@rcorre
Copy link

rcorre commented Apr 11, 2024

What OS are you using (uname -a, or Windows version)?

Windows 10, 19045.4291.

IE: 11.0.19041.3636

What programming language are you using (C/C++/Go/Rust)?

C++, MSVC v142

What did you expect to see and what you saw instead?

If I try to use set_html with a string longer than 1,572,834 characters on windows, the HTML never loads. The devtools inspector shows an empty HTML document. A string of exactly 1,572,834 characters loads fine and quickly, but 1,572,835 never loads. FWIW, I suspect that due to UTF-16 conversion in widen_string, the string is effectively doubled in size.

I cannot repro this on mac, and have been able to use set_html with significantly longer strings there.

You can repro with the attached script, just pass the desired html size as an argument:

#include <iostream>
#include <string>
#include "webview.h"

int main( int argc, char* argv[] )
{
    if ( argc < 2 ) {
        std::cerr << "Usage: ./example <size>" << std::endl;
        return -1;
    }
    int size = std::stoi( argv[ 1 ]);
    std::cout << "Using HTML of size: " << size << std::endl;
    std::string html( size, 'a');

    ::webview::webview w( true, nullptr );
    w.set_title( "example");
    w.set_size( 1024, 512, WEBVIEW_HINT_NONE );
    w.set_html( html );
    w.run();
    return 0;
}
@SteffenL
Copy link
Collaborator

Thanks for the report.

I checked the documentation of WebView2 and it states the following:

The htmlContent parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size. The origin of the new page is about:blank.

1,572,834 characters is closer to 3 MB after conversion to UTF-16.

I suspect the only way around that is to navigate to a file, virtual hostname or with a custom URI scheme, but those need to be implemented in the library unless you use the native handles and do it yourself.

@rcorre
Copy link
Author

rcorre commented Apr 12, 2024

Ah, thank you! I was searching for a documented limitation but couldn't find it.

@ammatwain
Copy link

I know this is a different context, but I've recently been using QWebViewEngine (which is a Chomium wrapper) of the QT libraries. And, on the setHtml method documentation we read, “Content larger than 2 MB cannot be displayed, because setHtml() converts the provided HTML to percent-encoding and places data: in front of it to create the URL that it navigates to.”

https://doc.qt.io/qt-6/qwebengineview.html#setHtml

@SteffenL
Copy link
Collaborator

I'm not quite sure exactly how the numbers add up to 2 MiB but here's my partial guess.

Length Data
29 data:text/html;charset=utf-8,
1572834 content
1 null

These numbers add up to 1572864 bytes or 1.5 MiB before conversion to UTF-16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants