Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

javascript - How to cancel webRequest silently in chrome extension

I'm re-posting my question from Chromium-extensions google group here.

In my extension, I want to cancel some webRequests based on url pattern. My problem is that, if I return {cancel:true} in the onBeforeRequest event listener, the browser would redirect to a page telling me that the request is blocked by some extension. But I just want to cancel the request silently(as nothing happened).

I have also tried to return {redirectUrl:""} in the onBeforeRequest event listener, the console would log an error saying that "" was not a valid URL, and a bar appeared at the bottom of the browser, saying "Waiting for extension". To dismiss that bar, I then run content script "window.stop()" in that web page. That works sometimes, but not always. So I wonder if someone has any better solution. Thanks!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use "javascript:" url instead :

{
    redirectUrl:"javascript:"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...