简体   繁体   English

在chrome中阻止webRequest处理程序中使用异步调用

[英]Use async calls in a blocking webRequest handler in chrome

I'm developing an extension that reads a database (firebase for now) info before redirecting the user to another page. 我正在开发一个扩展,在将用户重定向到另一个页面之前读取数据库(firebase for now)信息。

Right now I have successfully implemented the logic of static redirect by simply doing: 现在我只需执行以下操作即可成功实现静态重定向的逻辑:

function examineUrl(details) {
  return {redirectUrl: 'https://www.example.com/'};
}

Then I would love to implement the async logic of reading from database. 然后我想实现从数据库读取的异步逻辑。 I read in Use asynchronous calls in a blocking webRequest handler (It is a similar question but for firefox) that I can return a Promise, so I try that: 我在阻塞webRequest处理程序中读取使用异步调用 (这是一个类似的问题,但对于firefox)我可以返回一个Promise,所以我尝试:

function examineUrl(details) {
    return new Promise(function(resolve, reject) {
        return resolve( {redirectUrl: 'https://www.example.com/'})
    });
}

But there is no redirect action happening in chrome. 但是chrome中没有重定向动作。 The documentation for chrome did not mention it https://developer.chrome.com/extensions/webRequest , either. chrome的文档也没有提到https://developer.chrome.com/extensions/webRequest So I wonder if there exists a workaround for this in chrome? 所以我想知道在Chrome中是否存在解决方法?

As the comment goes, there is no such support in chrome. 正如评论所说,Chrome中没有这样的支持。

My workaround is to embrace the asynchronous pattern by reading data in a different asynchronous block instead of inside the webRequest handler -- kudos for code restructure for a better implementation! 我的解决方法是通过读取不同异步块中的数据而不是webRequest处理程序中的数据来接受异步模式 - 为了更好的实现而进行代码重构的荣誉!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM