8000 GitHub - acrool/acrool-window-launcher: This is a window launcher for front-end compatibility with browser issues when using window.open.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

acrool/acrool-window-launcher

Repository files navigation

Acrool Window Launcher

Acrool Window Launcher Logo

This is a window launcher for front-end compatibility with browser issues when using window.open.

NPM npm npm

npm downloads npm

Features

  • Supports window.open after asynchronous requests in iOS Safari.
  • Supports whether to close the old window when opening a new one
  • Provides browser detection (Safari, Firefox, IE, Wechat, Line, Facebook), default is Chrome.

Installation

yarn add @acrool/window-launcher

Examples

use in your page/component:

import {Launcher} from '@acrool/window-launcher';

const launcher = new Launcher({
    readyUrl: '/loading.html',
    isEnableCatchClose: true,
});
  1. open loading page
  2. xhr requet
  3. replace loading page to new url

Open URL

launcher
    .open(async () => {
        const json = await axios.get('/url1.json');
        return json.data.gameUrl;
        // or
        // return {
        //     type: 'url',
        //     value: json.data.html,
        // };
    })
    .catch(e => {
        logRef.current.append('\ncatch...');
    })
    .finally(() => {
        logRef.current.append('\nfinally...');
    });

Open HTML

launcher
    .open(async () => {
        const json = await axios.get('/html.json');
        return {
            type: 'html',
            value: json.data.html,
        };
    })
    .catch(e => {
        logRef.current.append('\ncatch...');
    })
    .finally(() => {
        logRef.current.append('\nfinally...');
    });

Open BLOB

ex: pdf preview

let url = '';
launcher
    .open(async () => {
        const json = await axios.get('/blob.json');

        url = URL.createObjectURL(base64ToBlob(res.buffer, res.mimeType));
        return url;
    })
    .catch(e => {
        logRef.current.append('\ncatch...');
    })
    .finally((url) => {
        URL.revokeObjectURL(url);
        
        logRef.current.append('\nfinally...');
    });

Check Browser

import Launcher, {
    checkIsMobile,
    checkIsAndroid,
    checkIsIOS,
    getBrowser,
    checkIsChromeBrowser,
    checkIsSafariBrowser,
    checkIsFirefoxBrowser,
    checkIsEdgeBrowser,
    checkIsLineBrowser,
    checkIsFacebookBrowser, checkIsWebview, checkIsPWA
} from '@acrool/window-launcher';

Check OS

import Launcher, {
    checkIsMobile,
    checkIsAndroid,
    checkIsIOS,
} from '@acrool/window-launcher';

In Global

Here, declare things that go in the global namespace, or augment existing declarations in the global namespace

typings/global.d.ts

import {Launcher} from '@acrool/window-launcher';

declare global {
    interface Window {
        ActiveXObject: string
        dataLayer: any[]
        launcher: Launcher
    }
}

tsconfig.json

{
    "files": [
        "typings/global.d.ts"
    ]
}

There is also a example that you can play with it:

Play react-editext-example

License

MIT © Acrool & Imagine

About

This is a window launcher for front-end compatibility with browser issues when using window.open.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

0