How to isolate two sessions while loading same webpage?


#1

Now suppose I have two BrowserWindows with two different sessions (say set by session.fromPartition('s1') and session.fromPartition('s2')), I assume the webRequest.onBeforeRequest method would apply separately to these two BrowserWindows as the sessions they are using are different. Also, none of these two sessions are session.defaultSession in this case.

But if I do

let s1 = session.fromPartition('persist:p1');
let s2 = session.fromPartition('persist:p2');
w1 = new BrowserWindow({ width: 640, height: 480, webPreferences: { session: s1 }});
w2 = new BrowserWindow({ width: 640, height: 480, webPreferences: { session: s2 }});

And change the s1.webRequest.onBeforeRequest to block all outgoing requests, nothing really gets blocked. Instead if I play with session.defaultSession.webRequest.onBeforeRequest all requests (including s2!) somehow are stopped perfectly. Does this mean the custom sessions I set do not take effect? If so, what am I missing?

Thanks in advance.