diff --git a/example.env b/example.env index 68cc24fd5..628607d4d 100644 --- a/example.env +++ b/example.env @@ -84,3 +84,6 @@ REDIS_URL= # set to "true" to enable mocked APIs in frontend. VITE_MOCK= + +# toggle playwright launching in headless +PLAYWRIGHT_HEADLESS= \ No newline at end of file diff --git a/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java b/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java index 29431d47a..ef3a0b916 100644 --- a/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java +++ b/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java @@ -9,6 +9,7 @@ import com.microsoft.playwright.Playwright; import com.microsoft.playwright.options.LoadState; import com.microsoft.playwright.options.ScreenshotType; +import jakarta.annotation.PostConstruct; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -21,6 +22,7 @@ import org.patinanetwork.codebloom.common.email.client.github.GithubOAuthEmailClient; import org.patinanetwork.codebloom.common.url.ServerUrlUtils; import org.patinanetwork.codebloom.scheduled.auth.CodeExtractor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component @@ -33,17 +35,25 @@ public class PlaywrightClient { private final ServerUrlUtils serverUrlUtils; private final EmailClient emailClient; + @Value("${playwright.headless}") + private boolean headless; + public PlaywrightClient(final ServerUrlUtils serverUrlUtils, GithubOAuthEmailClient githubOAuthEmailClient) { this.serverUrlUtils = serverUrlUtils; this.emailClient = githubOAuthEmailClient; } + @PostConstruct + private void logInfo() { + log.info("Headless: " + headless); + } + private T withPage(final Function consumer) { try (Playwright playwright = Playwright.create(); Browser browser = playwright .firefox() .launch(new BrowserType.LaunchOptions() - .setHeadless(true) + .setHeadless(headless) .setTimeout(40000)); BrowserContext context = browser.newContext( new NewContextOptions().setUserAgent(USER_AGENT).setStorageState(null)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3f4abd497..a77fe9535 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -118,3 +118,6 @@ app: jedis: url: ${REDIS_URL} + +playwright: + headless: ${PLAYWRIGHT_HEADLESS:true} \ No newline at end of file