Skip to content

Commit

Permalink
add contentWaitDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Dec 17, 2024
1 parent ee88689 commit cf267ca
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.codelibs.core.exception.IORuntimeException;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.core.lang.ThreadUtil;
import org.codelibs.core.misc.Tuple4;
import org.codelibs.core.stream.StreamUtil;
import org.codelibs.fess.crawler.Constants;
Expand Down Expand Up @@ -86,6 +87,8 @@ public class PlaywrightClient extends AbstractCrawlerClient {

protected static final String RENDERED_STATE = "renderedState";

protected static final String CONTENT_WAIT_DURATION = "contentWaitDuration";

protected static final String IGNORE_HTTPS_ERRORS_PROPERTY = "ignoreHttpsErrors";

protected static final String PROXY_BYPASS_PROPERTY = "proxyBypass";
Expand All @@ -106,6 +109,8 @@ public class PlaywrightClient extends AbstractCrawlerClient {

protected LoadState renderedState = LoadState.NETWORKIDLE;

protected long contentWaitDuration = 0;

protected Tuple4<Playwright, Browser, BrowserContext, Page> worker;

@Resource
Expand All @@ -128,6 +133,8 @@ public void init() {
renderedState = LoadState.valueOf(renderedStateParam);
}

contentWaitDuration = getInitParameter(CONTENT_WAIT_DURATION, 0L, Long.class);

final Boolean shared = getInitParameter(SHARED_CLIENT, Boolean.FALSE, Boolean.class);
if (shared) {
if (SHARED_WORKER == null) {
Expand Down Expand Up @@ -284,6 +291,11 @@ public ResponseData execute(final RequestData request) {

page.waitForLoadState(renderedState);

if (contentWaitDuration > 0L) {
logger.debug("Waiting {} ms before downloading the content.", contentWaitDuration);
ThreadUtil.sleep(contentWaitDuration);
}

if (logger.isDebugEnabled()) {
logger.debug("Loaded: Base URL: {}, Response URL: {}", url, response.url());
}
Expand Down

0 comments on commit cf267ca

Please sign in to comment.