Skip to content

Commit

Permalink
add system properties
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Oct 11, 2023
1 parent 7612b24 commit 5bf9ef9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class PlaywrightThumbnailGenerator extends BaseThumbnailGenerator {

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

protected Page.NavigateOptions navigateOptions;

protected double navigationTimeout = 30000;

@PostConstruct
public void init() {
final String lastaEnv = System.getProperty("lasta.env");
Expand All @@ -92,6 +96,8 @@ protected void createWorker() {
logger.debug("Initiaizing Playwright...");
}

updateProperties();

Playwright playwright = null;
Browser browser = null;
BrowserContext browserContext = null;
Expand All @@ -103,6 +109,7 @@ protected void createWorker() {
page = browserContext.newPage();
page.setViewportSize(viewportWidth, viewportHeight);
worker = new Tuple4<>(playwright, browser, browserContext, page);
navigateOptions = new Page.NavigateOptions().setTimeout(navigationTimeout);
available = true;
} catch (final Exception e) {
available = false;
Expand All @@ -114,6 +121,22 @@ protected void createWorker() {
}
}

protected void updateProperties() {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String viewportWidthStr = fessConfig.getSystemProperty("thumbnail.playwright.viewport.width");
if (viewportWidthStr != null) {
viewportWidth = Integer.valueOf(viewportWidthStr);
}
final String viewportHeightStr = fessConfig.getSystemProperty("thumbnail.playwright.viewport.height");
if (viewportHeightStr != null) {
viewportHeight = Integer.valueOf(viewportHeightStr);
}
final String navigationTimeoutStr = fessConfig.getSystemProperty("thumbnail.playwright.navigation.timeout");
if (navigationTimeoutStr != null) {
navigationTimeout = Double.valueOf(navigationTimeoutStr);
}
}

protected BrowserType getBrowserType(final Playwright playwright) {
if (logger.isDebugEnabled()) {
logger.debug("Create {}...", browserName);
Expand Down Expand Up @@ -188,7 +211,7 @@ protected synchronized void createScreenshot(final String url, final int width,
final Page page = worker.getValue4();
File tempPngFile = null;
try {
final Response response = page.navigate(url);
final Response response = page.navigate(url, navigateOptions);
page.waitForLoadState(renderedState);
if (logger.isDebugEnabled()) {
logger.debug("Loaded {} -> {}", url, response.url());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ protected boolean isSuppressTestCaseTransaction() {
@Override
public void setUp() throws Exception {
super.setUp();
generator = new PlaywrightThumbnailGenerator();
generator = new PlaywrightThumbnailGenerator() {
@Override
protected void updateProperties() {
}
};
final BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
launchOptions.setHeadless(true);
generator.addCondition("mimetype", "text/html");
Expand Down

0 comments on commit 5bf9ef9

Please sign in to comment.