net:ERR_UNSAFE_REDIRECT chrome при редиректе из расширения chrome
Я разрабатываю расширение для google chrome, моя задача выглядит примерно следущим образом:
- при помощи
chrome.webRequest.onBeforeRequestперехватить запрос - Предотвратить выполнение запроса (но не завершение его ошибкой) путем перенаправления его на ссылку вида
data:text/javascript;charset=utf-8,, то есть на пустой js.
Документация google chrome говорит, что для этого из функции, которая вызывается при событии onBeforeRequest, нужно вернуть объект вида
{ redirectUrl: 'data:text/javascript;charset=utf-8,'}
И судя по тексту документации:
redirectUrl Only used as a response to the onBeforeRequest and onHeadersReceived events. If set, the original request is prevented from being sent/completed and is instead redirected to the given URL. Redirections to non-HTTP schemes such as data: are allowed. Redirects initiated by a redirect action use the original request method for the redirect, with one exception: If the redirect is initiated at the onHeadersReceived stage, then the redirect will be issued using the GET method. Redirects from URLs with ws:// and wss:// schemes are ignored.
Редирект на data: URL'ы вполне легален. Однако при попытке сделать такой редирект, браузер блокирует запрос с ошибкой net:ERR_UNSAFE_REDIRECT.
Что я делаю не так?
P.S. обработчик на событие я навешиваю вот так:
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["<all_urls>"]}, ["blocking"]);
А в mainfest.json permisions я указал:
"permissions": [ "webNavigation", "tabs", "webRequest", "webRequestBlocking", "<all_urls>", "notifications", "storage", "contextMenus", "unlimitedStorage" ],