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

WebResourceRequested goes into an infinite loop if you give it an IStream #74

Closed
wravery opened this issue Nov 19, 2019 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@wravery
Copy link

wravery commented Nov 19, 2019

I haven't tested any prior versions, but in version 0.8.314 returning a content IStream through the IWebView2WebResourceResponse interface sends webview2 into an infinite loop. I think the IStream::Read loop has a bug in its termination condition:

embeddedbrowserwebview.dll!embedded_browser_webview_current::internal::ReadContentStreamIntoStringStream(IStream * content_stream, std::__1::basic_stringstream<char,std::__1::char_traits<char>,std::__1::allocator<char>> & string_stream) Line 82

Here's a simplified sample showing what I'm trying to do in the IWebView2WebResourceRequestedEventHandler callback:

constexpr auto c_fakeBody = R"htm(<html>
	<head>
		<title>Fake Body</title>
	</head>
	<body>
		<pre>Lorem ipsum...</pre>
	</body>
</html>)htm"sv;

constexpr auto c_fakeBodySize = static_cast<ULONG>(c_fakeBody.size() * sizeof(*c_fakeBody.data()));

// I get the URL of the request and compare it to the expected value before proceeding...

Microsoft::WRL::ComPtr<IWebView2WebResourceResponse> response;
Microsoft::WRL::ComPtr<IWebView2HttpResponseHeaders> headers;
Microsoft::WRL::ComPtr<IStream> content;
ULONG cbWritten = 0;
ULARGE_INTEGER uliSize{};

uliSize.QuadPart = static_cast<ULONGLONG>(c_fakeBodySize);

if (SUCCEEDED(CreateStreamOnHGlobal(NULL, true, &content))
	&& SUCCEEDED(content->Write(c_fakeBody.data(), c_fakeBodySize, &cbWritten))
	&& cbWritten == c_fakeBodySize
	&& SUCCEEDED(content->SetSize(uliSize))
	&& SUCCEEDED(content->Seek(LARGE_INTEGER{}, STREAM_SEEK_SET, nullptr))
	&& SUCCEEDED(environment->CreateWebResourceResponse(content.Get(), 200, L"OK", L"", &response))
	&& SUCCEEDED(response->get_Headers(&headers))
	&& SUCCEEDED(headers->AppendHeader(L"Content-Type", L"text/html")))
{
	args->put_Response(response.Get());
}
@david-risney david-risney added the bug Something isn't working label Nov 19, 2019
@david-risney
Copy link
Contributor

Great bug report, thanks! Let me look into this and get back to you.

@david-risney
Copy link
Contributor

Yes just like you said an issue in the Read loop termination condition. We'll look into this. Thanks!

@yildirimcagri-msft
Copy link
Member

yildirimcagri-msft commented Nov 25, 2019

Thanks for reporting this! We have the fix in the works. In the meantime if you need a workaround I recommend using SHCreateMemStream, which should not run into this issue because its IStream::Read returns S_FALSE when reached end of stream.

@pagoe-msft
Copy link

Happy to report that we just shipped updates to our WebResourceRequested Event in 0.8.355. Closing the issue for now and feel free to re-open the issue and let us know if you have additional feedback.

@wravery
Copy link
Author

wravery commented Dec 11, 2019

Just verified the fix, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants