Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

safe-open

yyz945947732126MIT1.0.5TypeScript support: included

A small utility to safely open URLs, upgrading http to https when necessary.

open-url, open, opener, opens, url, urls

readme

safe-open

A small utility to safely open URLs, upgrading http to https when necessary.

This is meant to be used in browser, not in the node environment.

Version Coverage Status PRs Welcome GitHub license

Why?

Modern browsers may block http:// URLs when opened from an https:// page due to mixed content restrictions. s​afe-open ensure http:// URLs are automatically upgraded to https:// when the current page uses HTTPS.

Note: This requires the original URL itself to support HTTPS.

Install

npm install safe-open
yarn add safe-open
pnpm install safe-open

Usage

import open from 'safe-open';

// Open 'https://www.google.com' if the current page is served over HTTPS
open('http://www.google.com');

// Specify target window (e.g., same tab)
open('http://www.google.com', '_self');

// Specify window features
open('http://www.google.com', 'mozillaWindow', 'popup');

API

open(url?, target?, features?)

This function follows the same signature as window.open.

Parameters

  • url (string) – The URL to open. If the page is HTTPS and the URL starts with http://, it will be automatically converted to https://.
  • target (string) – Specifies where to open the URL (_blank, _self, etc.).
  • features (string) – Additional window features such as size or position.

LICENSE

MIT


This project is created using generator-stupid.