XXX-domain GET

    @@ -16,9 +16,13 @@ // timeout // https://gist.github.com/noromanba/7e76cd75d15e27b102007298a8156d8f + // TBD Promise based functionize const controller = new AbortController(); const signal = controller.signal; - const TIMEOUT = 5000; + const TIMEOUT = 1000 * 10; + signal.onabort = () => { + console.warn(`timeout: ${TIMEOUT} sec elapsed`); + }; const timer = setTimeout(() => controller.abort(), TIMEOUT); const PROXY = 'https://cors-anywhere.herokuapp.com/';
  • /*
     * @title XXX-domain GET
     * @description XXX cross-domain GET over CORS abstract
     * @include http://*
     * @include https://*
     * @license MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // c.f.
    // https://robwu.nl/cors-anywhere.html
    // https://cors-anywhere.herokuapp.com
    //  https://github.com/Rob--W/cors-anywhere/
    (() => {
        'use strict';
    
        // timeout
        // https://gist.github.com/noromanba/7e76cd75d15e27b102007298a8156d8f
        // TBD Promise based functionize
        const controller = new AbortController();
        const signal = controller.signal;
        const TIMEOUT = 1000 * 10;
        signal.onabort = () => {
            console.warn(`timeout: ${TIMEOUT} sec elapsed`);
        };
        const timer = setTimeout(() => controller.abort(), TIMEOUT);
    
        const PROXY = 'https://cors-anywhere.herokuapp.com/';
    
        const url = 'https://example.com';
    
        // https://github.com/Rob--W/cors-anywhere/#example
        // `:443` not in use?
        //fetch(PROXY + url + new URL(url).protocol === 'https' ? ':443' : '', {
        fetch(PROXY + url , {
            mode: 'cors',
            signal,
        })
        .then(res => {
            if (!res.ok) {
                return Promise.reject(new Error(res.status, res.statusText));
            }
            return res.text();
        })
        .then(data => {
            // do something
            console.dir(data);
            return data;
        })
        .catch(err => {
            console.warn(err.message, err);
        })
        .finally(() => {
            clearTimeout(timer);
            console.log('settled');
        });
    })();
    
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/05/30 07:34:14 - 2018-05-30
  2. 2018/05/19 15:25:35 - 2018-05-19
  3. 2018/05/19 14:57:15 - 2018-05-19
  4. 2018/05/19 14:29:10 - 2018-05-19
  5. 2018/05/19 14:28:10 - 2018-05-19
  6. 2018/05/18 22:14:19 - 2018-05-18
  7. 2018/05/18 22:13:39 - 2018-05-18
  8. 2018/05/18 22:04:11 - 2018-05-18
  9. 2018/05/18 21:54:42 - 2018-05-18