Browser polyfill

Author: d | 2025-04-24

★★★★☆ (4.9 / 2599 reviews)

Download allegorithmic substance painter x64

Polyfill-js.cn is a service which accepts a request for a set of browser features and returns only the polyfills that are needed by the requesting browser. Polyfill-js.cn Polyfill JS CDN

essential programs

browser-polyfill/ at master expo/browser-polyfill - GitHub

Prevent injection attacks.Avoid XSS vulnerabilities. Stored data could be vulnerable to XSS if output directly to the page. Encode any output from web storage.Through following security best practices, developers can safely leverage the benefits of web storage while mitigating risks. Being mindful of the client-side nature of web storage is critical.Browser SupportThe browser support for Web Storage APIs is generally good across modern browsers. Here are some key details:Session Storage and Local Storage have broad support in all primary desktop and mobile browsers, including Chrome, Firefox, Safari, Edge, and Opera. Cookies have near-universal support across major browsers.IndexedDB has good support across most modern browsers but lacks support in older browsers like IE10 and below.To handle limited browser support, polyfills and fallbacks can be implemented:LocalForage provides an IndexedDB polyfill that falls back to WebSQL and LocalStorage.A common fallback for SessionStorage is storing data in memory on the client side.Cookies can be a fallback for LocalStorage when browser support is limited.Web Storage enjoys broad support across browsers, but fallbacks should be implemented for maximum compatibility. The right polyfill brings IndexedDB support to older browsers. Cookies remain a tried and true storage mechanism with near-universal backing.ConclusionWeb storage is helpful in many common scenarios like storing user preferences, caching data to improve performance, and persisting data when offline. The Web Storage API provides simple synchronous key-value storage through localStorage and sessionStorage objects.When using web storage, it's essential to be mindful of browser support, security implications, and storage limits. Usage will likely grow as web Polyfill-js.cn is a service which accepts a request for a set of browser features and returns only the polyfills that are needed by the requesting browser. Polyfill-js.cn Polyfill JS CDN Minimal repro repo: happens with both v0.2.1 on npm and when built from commit 2537b23.SummaryIf a browser.runtime.onMessage callback does not return a Promise, browser.runtime.sendMessage will be rejected with the following error, causing noise in the console:"The message port closed before a response was received."WorkaroundEven if you don't want to send a response, always return a promisein your onMessage callback: { console.log("background: onMessage", message); // Add this line: return Promise.resolve("Dummy response to keep the console quiet");});">// background.jsbrowser.runtime.onMessage.addListener(message => { console.log("background: onMessage", message); // Add this line: return Promise.resolve("Dummy response to keep the console quiet");});You can also make the onMessage callback async to implicitly return a Promise (resolving to undefined in the below example). { console.log("background: onMessage", message);});">// background.js// Notice the `async` keyword.browser.runtime.onMessage.addListener(async message => { console.log("background: onMessage", message);});FilesCopied over for convenience from: ], "js": [ "browser-polyfill-master.js", "content.js" ] } ]}">{ "manifest_version": 2, "version": "0.0.0", "name": "Test", "background": { "scripts": [ "browser-polyfill-npm.js", "background.js" ] }, "content_scripts": [ { "matches": [ "" ], "js": [ "browser-polyfill-master.js", "content.js" ] } ]}// background.jsbrowser.runtime.onMessage.addListener(onMessage);function onMessage(message) { console.log("background: onMessage", message); // 1: Causes the following to be logged in content: // "The message port closed before a response was received." return undefined; // 2: Causes this response to be logged in content, as expected. // return Promise.resolve("response from background"); // 3: Causes this error to be logged in content, as expected. // return Promise.reject(new Error("Could not respond")); // 4: Causes nothing at all to be logged in content! // I guess it is waiting for the deprecated `sendResponse` parameter to be // called. // return true;} {// console.log("content: callback", response, chrome.runtime.lastError);// });// console.log(// "content: after chrome.runtime.sendMessage with callback",// chrome.runtime.lastError// );">// content.js// 1: Unless background returns a Promise in its onMessage, this promise is// rejected with:// "The message port closed before a response was received."browser.runtime .sendMessage("hello from content") .then(console.log, console.error);// 2: This does not seem to cause any errors:// chrome.runtime.sendMessage("hello from content");// console.log("content: after chrome.runtime.sendMessage", chrome.runtime.lastError);// 3: Inside the callback, `chrome.runtime.lastError` will be:// "The message port closed before a response was received."// It seems like if `sendMessage` defines a callback but the other end doesn't// respond, Chrome is treating that as an error. Which makes sense.// The question is how this should be handled in a Promise based API.// chrome.runtime.sendMessage("hello from content", response => {// console.log("content: callback", response, chrome.runtime.lastError);// });// console.log(// "content: after chrome.runtime.sendMessage with callback",// chrome.runtime.lastError// );Solution?Should the "The message port closed before a response was received." be detected, and the promise should be resolved with undefined?

Comments

User5180

Prevent injection attacks.Avoid XSS vulnerabilities. Stored data could be vulnerable to XSS if output directly to the page. Encode any output from web storage.Through following security best practices, developers can safely leverage the benefits of web storage while mitigating risks. Being mindful of the client-side nature of web storage is critical.Browser SupportThe browser support for Web Storage APIs is generally good across modern browsers. Here are some key details:Session Storage and Local Storage have broad support in all primary desktop and mobile browsers, including Chrome, Firefox, Safari, Edge, and Opera. Cookies have near-universal support across major browsers.IndexedDB has good support across most modern browsers but lacks support in older browsers like IE10 and below.To handle limited browser support, polyfills and fallbacks can be implemented:LocalForage provides an IndexedDB polyfill that falls back to WebSQL and LocalStorage.A common fallback for SessionStorage is storing data in memory on the client side.Cookies can be a fallback for LocalStorage when browser support is limited.Web Storage enjoys broad support across browsers, but fallbacks should be implemented for maximum compatibility. The right polyfill brings IndexedDB support to older browsers. Cookies remain a tried and true storage mechanism with near-universal backing.ConclusionWeb storage is helpful in many common scenarios like storing user preferences, caching data to improve performance, and persisting data when offline. The Web Storage API provides simple synchronous key-value storage through localStorage and sessionStorage objects.When using web storage, it's essential to be mindful of browser support, security implications, and storage limits. Usage will likely grow as web

2025-03-30
User2212

Minimal repro repo: happens with both v0.2.1 on npm and when built from commit 2537b23.SummaryIf a browser.runtime.onMessage callback does not return a Promise, browser.runtime.sendMessage will be rejected with the following error, causing noise in the console:"The message port closed before a response was received."WorkaroundEven if you don't want to send a response, always return a promisein your onMessage callback: { console.log("background: onMessage", message); // Add this line: return Promise.resolve("Dummy response to keep the console quiet");});">// background.jsbrowser.runtime.onMessage.addListener(message => { console.log("background: onMessage", message); // Add this line: return Promise.resolve("Dummy response to keep the console quiet");});You can also make the onMessage callback async to implicitly return a Promise (resolving to undefined in the below example). { console.log("background: onMessage", message);});">// background.js// Notice the `async` keyword.browser.runtime.onMessage.addListener(async message => { console.log("background: onMessage", message);});FilesCopied over for convenience from: ], "js": [ "browser-polyfill-master.js", "content.js" ] } ]}">{ "manifest_version": 2, "version": "0.0.0", "name": "Test", "background": { "scripts": [ "browser-polyfill-npm.js", "background.js" ] }, "content_scripts": [ { "matches": [ "" ], "js": [ "browser-polyfill-master.js", "content.js" ] } ]}// background.jsbrowser.runtime.onMessage.addListener(onMessage);function onMessage(message) { console.log("background: onMessage", message); // 1: Causes the following to be logged in content: // "The message port closed before a response was received." return undefined; // 2: Causes this response to be logged in content, as expected. // return Promise.resolve("response from background"); // 3: Causes this error to be logged in content, as expected. // return Promise.reject(new Error("Could not respond")); // 4: Causes nothing at all to be logged in content! // I guess it is waiting for the deprecated `sendResponse` parameter to be // called. // return true;} {// console.log("content: callback", response, chrome.runtime.lastError);// });// console.log(// "content: after chrome.runtime.sendMessage with callback",// chrome.runtime.lastError// );">// content.js// 1: Unless background returns a Promise in its onMessage, this promise is// rejected with:// "The message port closed before a response was received."browser.runtime .sendMessage("hello from content") .then(console.log, console.error);// 2: This does not seem to cause any errors:// chrome.runtime.sendMessage("hello from content");// console.log("content: after chrome.runtime.sendMessage", chrome.runtime.lastError);// 3: Inside the callback, `chrome.runtime.lastError` will be:// "The message port closed before a response was received."// It seems like if `sendMessage` defines a callback but the other end doesn't// respond, Chrome is treating that as an error. Which makes sense.// The question is how this should be handled in a Promise based API.// chrome.runtime.sendMessage("hello from content", response => {// console.log("content: callback", response, chrome.runtime.lastError);// });// console.log(// "content: after chrome.runtime.sendMessage with callback",// chrome.runtime.lastError// );Solution?Should the "The message port closed before a response was received." be detected, and the promise should be resolved with undefined?

2025-03-29
User8170

Date-fns-tzTime zone support for date-fns v2.0.0 using theIntl API. By usingthe browser API no time zone data needs to be included in code bundles. Modern browsers all support thenecessary features,and for those that don't a polyfill can be used.If you do not wish to use a polyfill the time zone option can still be used, but only withtime zone offsets such as '-0200' or '+04:00' and not IANA time zone names.Table of ContentsOverviewTime Zone HelperszonedTimeToUtc - Given a date and any time zone, returns a Date with the equivalent UTC timeutcToZonedTime - Get a date/time representing local time in a given time zone from the UTC dategetTimezoneOffset - Gets the offset in milliseconds between the time zone and UTC timeTime Zone Formattingformat - Extends date-fns/format with full time zone supporttoDate - Can be used to create a zoned Date from a string containing an offset or IANA time zoneUsage with Node.jsOverviewWorking with UTC or ISO date strings is easy, and so is working with JS dates when all timesare displayed in a user's local time in the browser. The difficulty comes when working with anothertime zone's local time, other than the current system's, like on a Node server or when showing the timeof an event in a specific time zone, like an event in LA at 8pm PST regardless of where a user resides.In this case there are two relevant pieces of information:a fixed moment in time in the form of a timestamp, UTC or ISO date string, andthe time zone descriptor, usually an offset or IANA time zone name (e.g. America/New_York).Libraries like Moment and Luxon, which provide their own date time classes, manage these timestamp and timezone values internally. Since date-fns always returns a plain JS Date, which implicitly has the currentsystem's time zone, helper functions are provided for

2025-04-18

Add Comment