MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: I want to use add_ebResourceRequested to make changes to the JS file, but it won't succeed.

Open
#5,327 0 comments 0 reactions 1 assignee View on GitHub

@dhveerap is already working on this.

Since Aug 18, 2025.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

the developer tool shows a network request error. Even using official examples SampleApps/WebView2APISample/ScenarioSharedWorkerWRR.cpp , use the same question.

wil::com_ptr<ICoreWebView2_22> webview222 = data->webview.try_query<ICoreWebView2_22>();
webview222 ->AddWebResourceRequestedFilterWithRequestSourceKinds(L"https://lf-webcast-platform.bytetos.com/obj/webcast-platform-cdn/webcast/douyin_live/*", COREWEBVIEW2_WEB_RESOURCE_CONTEXT_SCRIPT, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);
data->webview->add_WebResourceRequested(Callback<ICoreWebView2WebResourceRequestedEventHandler>(
    [data](ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args) -> HRESULT {
        wil::com_ptr<ICoreWebView2WebResourceRequest> request;
        args->get_Request(&request);
        wil::unique_cotaskmem_string uri;
        request->get_Uri(&uri);
        std::wstring url(uri.get());
        std::wstringstream ss(url);
        if (url.find(L".js") == std::string::npos)
        {
            return S_OK;
        }
        std::wstring segment;
        std::vector<std::wstring> arr;
        while (std::getline(ss, segment, L"/")) {
            arr.push_back(segment);
        }
        if (arr.size() != 8 || url.find(L"client") != std::string::npos || url.find(L"runtime") != std::string::npos || url.find(L"polyfill") != std::string::npos)
        {
            return S_OK;
        }
        std::wstring targetUri(uri.get());
        std::string originalJs = DownloadUrlContentA(targetUri);
        if (!originalJs.empty()) {
            std::string modifiedJs = ModifyJavaScript(originalJs);
            auto stream = SHCreateMemStream(
                reinterpret_cast<const BYTE*>(modifiedJs.data()),
                static_cast<UINT>(modifiedJs.size())
            );
            wil::com_ptr<ICoreWebView2WebResourceResponse> response;
            Microsoft::WRL::ComPtr<ICoreWebView2Environment> environment;
            Microsoft::WRL::ComPtr<ICoreWebView2_2> webview2;
            data->webview->QueryInterface(IID_PPV_ARGS(&webview2));
            webview2->get_Environment(&environment);
            environment->CreateWebResourceResponse(
                stream,
                200,
                L"OK",
                L"Content-Type: application/javascript; charset=utf-8",
                &response
            );
            args->put_Response(response.get());
            return S_OK;
        }
        return S_OK;
    }
).Get(), &data->webResourceToken);
Image
Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

138.0.3351.109

SDK Version

1.0.3351.48

Framework

Win32

Operating System

Windows 11

OS Version

1000.26100.128.0

Repro steps
  1. git clone https://github.com/MicrosoftEdge/WebView2Samples.git
  2. open WebView2GettingStarted.sln
  3. update Microsoft.Web.WebView2 1.0.3351.48 by NuGet
  4. change \GettingStartedGuides\Win32_GettingStarted\HelloWebView.cpp source code
  5. run
Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.