Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tooling to bundle a browser build #1253

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Oct 2, 2023

  1. add: 'browser-build'

    * uses WebPack to bundle the library into a single JS file,
      which can be downloaded by web browsers from a CDN
    * same-origin policy requires that this library
      can only be called from a page hosted by 'youtube.com',
      which limits the use-cases for this build to mainly:
      - browser extensions
      - userscripts
    
    status:
    =======
    * the example userscript indicates that the Promise returned from:
        window.ytdl.getInfo(window.location.href)
      catches an Error caused by the server response status code: 410
    * the corresponding request looks OK:
        https://www.youtube.com/get_video_info?video_id=...
      but something is clearly breaking;
      a closer look is required.
    warren-bank committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    7c618e0 View commit details
    Browse the repository at this point in the history
  2. fix: 'browser-build'

    * the issue was the dependency: 'miniget'
      - it performs a GET request,
        with some configurable behavior
      - it uses several native node modules,
        for which I had previously included polyfill libraries
      - ultimately, it just wasn't working
      - I replaced it with a mock implementation,
        which uses 'window.fetch' to perform the network request
    
    status:
    =======
    * the example userscript works great
    warren-bank committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    5d32703 View commit details
    Browse the repository at this point in the history

Commits on Oct 3, 2023

  1. update: 'browser-build'

    add support for:
      options.requestOptions.headers
      options.requestOptions.proxyUrl
      options.requestOptions.debug
    
    example:
    ========
      window.ytdl.getInfo(
        'https://www.youtube.com/watch?v=CICY20dQUPk',
        {
          requestOptions: {
            headers: {"x-requested-with": "ytdl-core"},
            proxyUrl: "https://cors-anywhere.herokuapp.com/",
            debug: false
          }
        }
      )
    
    where:
    ======
      https://cors-anywhere.herokuapp.com/corsdemo
    
    test temporary access to demo proxy server:
    ===========================================
    {
      const proxy  = 'https://cors-anywhere.herokuapp.com/'
      const target = 'http://httpbin.org/get'
      const url    = proxy + target
    
      fetch(url, {headers: {"x-requested-with": "ytdl-core"}})
      .then(req => req.text()).then(console.log)
    }
    
    related:
    ========
    * using with proxyAgent in node
        https://github.com/fent/node-ytdl-core/blob/v4.11.5/example/proxy.js
    * using with proxyUrl in browser
        https://www.npmjs.com/package/ytdl-core-browser
        https://www.npmjs.com/package/ytdl-core-info-browser
    
    notes:
    ======
    * 'cors-anywhere' limits 50 requests per hour per URL origin
      - apparently, this count is not per-user
      - as such, the example userscript tests on a low-traffic domain:
          'example.com'
    * using a proxyUrl, such as 'cors-anywhere', only works on sites
      having a permissive CSP that allows cross-origin fetch
      to 'www.youtube.com'
      - for example, it won't work on 'github.com'
    warren-bank committed Oct 3, 2023
    Configuration menu
    Copy the full SHA
    7025fe2 View commit details
    Browse the repository at this point in the history

Commits on Dec 4, 2023

  1. update: 'browser-build'

    in addition to the existing es2020 target,
    add a new es5 target.. along with examples.
    warren-bank committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    d5fa81f View commit details
    Browse the repository at this point in the history