electron: webContents's session can not enableNetworkEmulation
Win10
Electron 7.1.0 and Electron6.1.4
let { remote } = require("electron");
let ses = remote.getCurrentWebContents().session;
await ses.clearCache();
await ses.clearStorageData();
ses.enableNetworkEmulation({
offline: true
});
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.cnblogs.com/aggsite/AggStats");
xhr.onload = () => console.log(xhr.responseText);
xhr.send();
When I emulate the network outage, the xhr gets the web source correctly.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 16 (10 by maintainers)
Here’s a Fiddle which reproduces the issue: https://gist.github.com/7b6b11c8f57465aa2545e508f0e6d0f1
If it loads the webpage successfully, then this feature is broken.
I can reproduce this.
A little analysis: at least in the post-network-service code (7.x+), it looks like when we set the network conditions, we pass
network_emulation_token_, which is never anywhere set as thethrottling_profile_idof any request, so the network conditions are never applied.As a workaround for now, you might try using the Network.emulateNetworkConditions method in the debugger API, e.g.
NB. with this workaround, the network condition emulation will only last as long as the debugger is attached.