Is it possible to skip a request? #1215
-
I would like to implement some filter that could determine whether a request from the queue will be requested by the browser, or whether it should be skipped. Obviously, this is when the next request has already been received from the queue, but has not yet been passed to the browser. I thought preNavigationHooks was the way to go, but there's no access to the request there, nor any way to return any result. Can you tell me if it's possible to implement this? Maybe there is such a hook in BrowserCrawler or even in RequestQueueue? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Why are you adding requests you don't want to be executed into the queue in the first place? I'd say you should filter them right ahead. How are you adding the requests to the queue? If it's via |
Beta Was this translation helpful? Give feedback.
-
You do have access to the preNavigationHooks: [
async (crawlingContext, gotoOptions) => {
const { request } = crawlingContext;
request.noRetry = true;
throw new Error('Request cancelled.');
},
] |
Beta Was this translation helpful? Give feedback.
You do have access to the
request
. It's a property of thecrawlingContext
. There isn't any direct API to do this, but you can set the request to not retry and then throw.