gsioteam / kinoko

An online manga browser.
MIT License
260 stars 13 forks source link

Support headless browser and webview to login to a site #27

Closed winterdl closed 2 years ago

winterdl commented 2 years ago

The v3 plugin system is great, I could add new site easily, but it is great if the core support more functions for crawling:

gsioteam commented 2 years ago

Ok, I have a headless browser implementation in other project, I will implement it in Kinoko.

The headless browser api will look like this:

let webView = new HiddenWebView({
      // Replace the resource in the web site.
      resourceReplacements: [{
          test:'jwplayer\.js',
          resource: this.loadString('my_jwplayer.js'),
          mimeType: 'text/javascript',
      }]
  });
  let cleanUp = () => {
      this.webView = null;
  }; 
  webView.load(src);
  // Receive message 
  webView.onmessage = (ev) => {
      let event = ev.event;
      let data = ev.data;
      switch (event) {
          case 'complete': {
              let items = [];
              for (let source of data.sources) {
                  items.push({
                      title: source.label,
                      url: source.file
                  });
              }
              resolve(items);
              cleanUp();
              break;
          }
      }
  };
  // Hold the reference otherwise the webView will be free before it callback.
  this.webView = webView;
gsioteam commented 2 years ago

The webview api is added in v4.1.0, I put the usage here.

winterdl commented 2 years ago

Thank you for your support, I will test the headless webview.