Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1032326 // Playwright Module [youTubeSearch etc]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 65776K of libraries. Click here for Pure Java version (12144L/62K).

1  
!7
2  
3  
cm PlaywrightModule > DynPrintLogAndEnabled {
4  
  transient autoDispose new Borrowable<PlaywrightAndBrowser> sharedBrowser;
5  
  
6  
  start-thread {
7  
    time "Chromium preloaded" {
8  
      sharedBrowser.set(playwrightWithChromium());
9  
    }
10  
  }
11  
12  
  // borrow or create temporarily
13  
  PlaywrightAndBrowser acquireBrowser(IResourceHolder res) {
14  
    var borrowedBrowser = res.add(sharedBrowser.tempBorrow());
15  
    var browser = borrowedBrowser!;
16  
    if (browser == null)
17  
      browser = res.add(tempPlaywrightWithChromium());
18  
    else
19  
      print("Using borrowed browser");
20  
    ret browser;
21  
  }
22  
  
23  
  // API
24  
  
25  
  WithURL<S> youTubeSearch(S query) { print exceptions {
26  
      printFunctionCall youTubeSearch(query);
27  
      temp res = resourceHolder();
28  
      var browser = acquireBrowser(res);
29  
      ret print(result := main youTubeSearch(browser!, query));
30  
  }}
31  
  
32  
  WithURL<S> webSearch(S query) {
33  
    ret first(webSearch_all(query));
34  
  }
35  
  
36  
  L<WithURL<S>> webSearch_all(S query, MapSO urlParams default null) { print exceptions {
37  
    printFunctionCall webSearch_all(query);
38  
    temp res = resourceHolder();
39  
    var browser = acquireBrowser(res);
40  
    GoogleSearch gs = new(browser!, query);
41  
    addAll(gs.urlParams, urlParams);
42  
    ret print(result := googleSearch_all(gs));
43  
  }}
44  
  
45  
  BufferedImage screenShootWebsite(S url, double delay default 2.0) { print exceptions {
46  
    printFunctionCall screenShootWebsite(url, delay);
47  
    temp res = resourceHolder();
48  
    var browser = acquireBrowser(res);
49  
    temp page = playwrightOpenPage(browser!, url);
50  
    ret playwrightScreenshot(page, delay);
51  
  }}
52  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, uelavcdoioby

No comments. add comment

Snippet ID: #1032326
Snippet name: Playwright Module [youTubeSearch etc]
Eternal ID of this version: #1032326/18
Text MD5: 5f6389dd280db00f9c557a95882d7c16
Transpilation MD5: 3e1d3549e332b5c83d1cc58aa204350d
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-02 01:43:11
Source code size: 1635 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 248 / 71020
Version history: 17 change(s)
Referenced in: [show references]