Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ REDIS_URL=

# set to "true" to enable mocked APIs in frontend.
VITE_MOCK=

# toggle playwright launching in headless
PLAYWRIGHT_HEADLESS=
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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> T withPage(final Function<Page, T> 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));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ app:

jedis:
url: ${REDIS_URL}

playwright:
headless: ${PLAYWRIGHT_HEADLESS:true}