2 回答
![?](http://img1.sycdn.imooc.com/545850a00001fdd002200220-100-100.jpg)
TA贡献1780条经验 获得超4个赞
好的,这似乎比使用更好的方法protocol:
session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
if (details.url.indexOf('file://api./') == 0) { //TODO Change to regex & parametrize (optional - set default value)
//TODO Test it works with non-GET (should work - using 307 redirect)
callback({ redirectURL: `http://localhost/${details.url.substr(12)}` }); //TODO Parametrize (mandatory)
} else {
callback({}); //TODO Test this works
}
});
使用protocol应该仍然有效,但我认为它会使用interceptBufferProtocol:
protocol.interceptBufferProtocol('file', (request, result) => {
if (request.url.indexOf('file://api./') == 0) {
return result(new Buffer('{}')); //TODO Call API and return Buffer response (I suppose)
} else {
// FIXME What goes here!? As in "just continue doing what you would have done"
}
});
我仍然不知道如何在那里解决 FIXME,所以如果有人能回答,将不胜感激。
添加回答
举报