@vangware/window-open-promise

🪟 Promised Window.open();

Usage no npm install needed!

<script type="module">
  import vangwareWindowOpenPromise from 'https://cdn.skypack.dev/@vangware/window-open-promise';
</script>

README

Vangware's Window Open Promise

Build Status Coverage License NPM Version Open Issues

🪟 Promised Window.open();.

Usage

📦 Node

import { windowOpenPromise } from "@vangware/window-open-promise";

const windowOpen = windowOpenPromise(window);

windowOpen({
    url: "https://example.com", // URL is not required, you can open a blank window
    top: 10,
    left: 10,
})
    .then((newWindow) => {
        newWindow.console.log("This will log in the new window.");
        newWindow.addEventListener("beforeunload", (_event) => {
            console.log("This will log when the new window is closed.");
        });
    })
    .catch((_error) => {
        console.error("This will log if the new window can't be opened.");
    });

🦕 Deno

import { windowOpenPromise } from "https://cdn.skypack.dev/@vangware/window-open-promise?dts";

const windowOpen = windowOpenPromise(window);

try {
    const newWindow = await windowOpen({
        url: "https://example.com", // URL is not required, you can open a blank window
        top: 10,
        left: 10,
    });
    newWindow.console.log("This will log in the new window.");
    newWindow.addEventListener("beforeunload", (_event) => {
        console.log("This will log when the new window is closed.");
    });
} catch (_error) {
    console.error("This will log if the new window can't be opened.");
}

Documentation

Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.

Changelog

Changelog can be found HERE.

Test coverage

Test coverage can be found HERE.