Skip to content

Commit

Permalink
Connect to a remote instance using web sockets
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Nioche <[email protected]>
  • Loading branch information
jnioche authored and rzo1 committed Oct 21, 2024
1 parent f16bf8d commit b40f9db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions external/playwright/playwright-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ config:
http.timeout: 5000

# playwright.cdp.url: "http://localhost:9222"
# playwright.remote.ws: "ws://localhost:3000/"
playwright.skip.download: true
# com.microsoft.playwright.options.WaitUntilState
# playwright.load.event: "domcontentloaded"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.storm.Config;
import org.apache.storm.utils.MutableInt;
import org.apache.stormcrawler.Metadata;
Expand Down Expand Up @@ -81,6 +83,9 @@ public void configure(final Config conf) {
// "http://localhost:9222"
final String CDP_URL = ConfUtils.getString(conf, "playwright.cdp.url");

// "ws://localhost:3000/"
final String REMOTE_WS = ConfUtils.getString(conf, "playwright.remote.ws");

boolean skipDownloads = ConfUtils.getBoolean(conf, "playwright.skip.download", false);

String loadEventString = ConfUtils.getString(conf, "playwright.load.event", "load");
Expand All @@ -100,7 +105,8 @@ public void configure(final Config conf) {
final CreateOptions creationOptions = new CreateOptions();
final Map<String, String> env = new HashMap<>();

if (CDP_URL != null) {
// no need to download if we are connecting to a remote instance
if (StringUtils.isNotBlank(CDP_URL) || StringUtils.isNotBlank(REMOTE_WS)){
skipDownloads = true;
}

Expand All @@ -112,8 +118,14 @@ public void configure(final Config conf) {
creationOptions.setEnv(env);

BrowserType btype = Playwright.create(creationOptions).chromium();
if (CDP_URL != null) {
if (StringUtils.isNotBlank(CDP_URL) && StringUtils.isNotBlank(REMOTE_WS)){
throw new RuntimeException("Can't specify both cdp.url and remote.ws in the configuration");
}
else if (StringUtils.isNotBlank(CDP_URL)) {
browser = btype.connectOverCDP(CDP_URL);
}
else if (StringUtils.isNotBlank(REMOTE_WS)) {
browser = btype.connect(REMOTE_WS);
} else {
browser = btype.launch();
}
Expand Down

0 comments on commit b40f9db

Please sign in to comment.