Code Monkey home page Code Monkey logo

window-open-promise's Introduction

This repository's code was moved to lou.codes.


Coverage License NPM Version Open Issues

๐ŸชŸ Promised Window.open();.

Usage

๐Ÿ“ฆ Node

Install @vangware/window-open-promise as a dependency:

pnpm add @vangware/window-open-promise
# or
npm install @vangware/window-open-promise
# or
yarn add @vangware/window-open-promise

Import it and use it:

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

const windowOpen = windowOpenPromise(globalThis);

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 @vangware/window-open-promise using the npm: prefix, and use it directly:

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

const windowOpen = windowOpenPromise(globalThis);

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.");
}

๐ŸŒŽ Browser

Import @vangware/window-open-promise using esm.sh, and use it directly:

<script type="module">
	import { windowOpenPromise } from "https://esm.sh/@vangware/window-open-promise";

	const windowOpen = windowOpenPromise(globalThis);

	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.");
	}
</script>

Useful links

window-open-promise's People

Contributors

loucyx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

window-open-promise's Issues

Missing module declaration

Using this library for a long time, ignoring the following error whenever I open the file importing the library.

Unable to resolve the path to module '@vangware/window-open-promise.' eslint[import/no-unresolved] ...

Is it intentional not specifying the module prop to the file which holds all exports? Installing the library, only "type": "module" is set, but the corresponding module declaration is missing. Adding "module": "./dist/index.js" after installing the library fixes the problem.

Thx!

Error on Google Chrome

When opening promised window on Chrome I got this error

A boolean is being passed as a fourth parameter to window.open. This is not used and may cause an exception in a future release.

Stopped working since 2.5.1

A few days ago, with the release of 2.5.1, something broke. It was working perfectly fine with 2.5.0. The version change got declared as a patch. Something that small should not break large even when you refactored micro entirely. Looking at the dependencies involved in your project and the error message gets thrown, something has changed in micro. Has window-open-promise imported from micro before 2.5.1 also consuming the ESM module?

The exception I get is the following. Looking at the implementation of micro, the new typescript operator ?? gets used, but why gets this not converted into unreadable javascript, does it relate with the typescript lib ES2018 used in typescript compilation?

Maybe you can have a look,
Thx!

./node_modules/@vangware/micro/esm/arrayGroup.js 23:56
Module parse failed: Unexpected token (23:56)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     return {
|         ...groups,
>         [groupName]: arrayPush(item)(groups[groupName] ?? [])
|     };
| })({});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.