@uekichinos/browser-gate 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/index.cjs +21 -10
- package/dist/index.global.js +21 -10
- package/dist/index.js +21 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@uekichinos/browser-gate` are documented here.
|
|
4
4
|
|
|
5
|
+
## [0.1.1] - 2026-04-11
|
|
6
|
+
### Fixed
|
|
7
|
+
- Use `location.replace()` instead of `location.href` for redirect — prevents back-navigation to the blocked page
|
|
8
|
+
|
|
9
|
+
### Improved
|
|
10
|
+
- `checkLatest` now caches the endoflife.date API response in `sessionStorage` — skips the network request on subsequent calls within the same session
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Socket.dev badge in README
|
|
14
|
+
|
|
5
15
|
## [0.1.0] - 2026-04-11
|
|
6
16
|
### Added
|
|
7
17
|
- Initial release
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @uekichinos/browser-gate
|
|
2
2
|
|
|
3
|
+
[](https://badge.socket.dev/npm/package/@uekichinos/browser-gate/0.1.0)
|
|
4
|
+
|
|
3
5
|
Detect outdated browsers and redirect or block access. Supports three detection modes — use one, two, or all three together.
|
|
4
6
|
|
|
5
7
|
- **Feature detection** (default) — checks for modern browser APIs
|
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ var ENDOFLIFE_URLS = {
|
|
|
58
58
|
edge: "https://endoflife.date/api/edge.json"
|
|
59
59
|
};
|
|
60
60
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
61
|
+
var CACHE_KEY_PREFIX = "bgv:";
|
|
61
62
|
async function checkLatestVersion(browser, tolerance = 0) {
|
|
62
63
|
if (browser.name === "unknown" || browser.version === null) {
|
|
63
64
|
return { passed: true };
|
|
@@ -65,15 +66,25 @@ async function checkLatestVersion(browser, tolerance = 0) {
|
|
|
65
66
|
const url = ENDOFLIFE_URLS[browser.name];
|
|
66
67
|
if (!url) return { passed: true };
|
|
67
68
|
try {
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
let latestCycle = null;
|
|
70
|
+
const cacheKey = `${CACHE_KEY_PREFIX}${browser.name}`;
|
|
71
|
+
const cached = sessionStorage.getItem(cacheKey);
|
|
72
|
+
if (cached !== null) {
|
|
73
|
+
latestCycle = parseInt(cached, 10);
|
|
74
|
+
} else {
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
77
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (!res.ok) return { passed: true };
|
|
80
|
+
const data = await res.json();
|
|
81
|
+
if (!Array.isArray(data) || data.length === 0) return { passed: true };
|
|
82
|
+
latestCycle = parseInt(data[0].cycle, 10);
|
|
83
|
+
if (!isNaN(latestCycle)) {
|
|
84
|
+
sessionStorage.setItem(cacheKey, String(latestCycle));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (latestCycle === null || isNaN(latestCycle)) return { passed: true };
|
|
77
88
|
const diff = latestCycle - browser.version;
|
|
78
89
|
if (diff > tolerance) {
|
|
79
90
|
return {
|
|
@@ -151,7 +162,7 @@ async function browserGate(options) {
|
|
|
151
162
|
if (options.onOutdated) {
|
|
152
163
|
options.onOutdated(info);
|
|
153
164
|
} else if (options.redirect) {
|
|
154
|
-
window.location.
|
|
165
|
+
window.location.replace(options.redirect);
|
|
155
166
|
}
|
|
156
167
|
}
|
|
157
168
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.global.js
CHANGED
|
@@ -58,6 +58,7 @@ var BrowserGate = (() => {
|
|
|
58
58
|
edge: "https://endoflife.date/api/edge.json"
|
|
59
59
|
};
|
|
60
60
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
61
|
+
var CACHE_KEY_PREFIX = "bgv:";
|
|
61
62
|
async function checkLatestVersion(browser, tolerance = 0) {
|
|
62
63
|
if (browser.name === "unknown" || browser.version === null) {
|
|
63
64
|
return { passed: true };
|
|
@@ -65,15 +66,25 @@ var BrowserGate = (() => {
|
|
|
65
66
|
const url = ENDOFLIFE_URLS[browser.name];
|
|
66
67
|
if (!url) return { passed: true };
|
|
67
68
|
try {
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
let latestCycle = null;
|
|
70
|
+
const cacheKey = `${CACHE_KEY_PREFIX}${browser.name}`;
|
|
71
|
+
const cached = sessionStorage.getItem(cacheKey);
|
|
72
|
+
if (cached !== null) {
|
|
73
|
+
latestCycle = parseInt(cached, 10);
|
|
74
|
+
} else {
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
77
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (!res.ok) return { passed: true };
|
|
80
|
+
const data = await res.json();
|
|
81
|
+
if (!Array.isArray(data) || data.length === 0) return { passed: true };
|
|
82
|
+
latestCycle = parseInt(data[0].cycle, 10);
|
|
83
|
+
if (!isNaN(latestCycle)) {
|
|
84
|
+
sessionStorage.setItem(cacheKey, String(latestCycle));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (latestCycle === null || isNaN(latestCycle)) return { passed: true };
|
|
77
88
|
const diff = latestCycle - browser.version;
|
|
78
89
|
if (diff > tolerance) {
|
|
79
90
|
return {
|
|
@@ -151,7 +162,7 @@ var BrowserGate = (() => {
|
|
|
151
162
|
if (options.onOutdated) {
|
|
152
163
|
options.onOutdated(info);
|
|
153
164
|
} else if (options.redirect) {
|
|
154
|
-
window.location.
|
|
165
|
+
window.location.replace(options.redirect);
|
|
155
166
|
}
|
|
156
167
|
}
|
|
157
168
|
return __toCommonJS(index_exports);
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var ENDOFLIFE_URLS = {
|
|
|
32
32
|
edge: "https://endoflife.date/api/edge.json"
|
|
33
33
|
};
|
|
34
34
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
35
|
+
var CACHE_KEY_PREFIX = "bgv:";
|
|
35
36
|
async function checkLatestVersion(browser, tolerance = 0) {
|
|
36
37
|
if (browser.name === "unknown" || browser.version === null) {
|
|
37
38
|
return { passed: true };
|
|
@@ -39,15 +40,25 @@ async function checkLatestVersion(browser, tolerance = 0) {
|
|
|
39
40
|
const url = ENDOFLIFE_URLS[browser.name];
|
|
40
41
|
if (!url) return { passed: true };
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
let latestCycle = null;
|
|
44
|
+
const cacheKey = `${CACHE_KEY_PREFIX}${browser.name}`;
|
|
45
|
+
const cached = sessionStorage.getItem(cacheKey);
|
|
46
|
+
if (cached !== null) {
|
|
47
|
+
latestCycle = parseInt(cached, 10);
|
|
48
|
+
} else {
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
51
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
if (!res.ok) return { passed: true };
|
|
54
|
+
const data = await res.json();
|
|
55
|
+
if (!Array.isArray(data) || data.length === 0) return { passed: true };
|
|
56
|
+
latestCycle = parseInt(data[0].cycle, 10);
|
|
57
|
+
if (!isNaN(latestCycle)) {
|
|
58
|
+
sessionStorage.setItem(cacheKey, String(latestCycle));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (latestCycle === null || isNaN(latestCycle)) return { passed: true };
|
|
51
62
|
const diff = latestCycle - browser.version;
|
|
52
63
|
if (diff > tolerance) {
|
|
53
64
|
return {
|
|
@@ -125,7 +136,7 @@ async function browserGate(options) {
|
|
|
125
136
|
if (options.onOutdated) {
|
|
126
137
|
options.onOutdated(info);
|
|
127
138
|
} else if (options.redirect) {
|
|
128
|
-
window.location.
|
|
139
|
+
window.location.replace(options.redirect);
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uekichinos/browser-gate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Detect outdated browsers and redirect or block access. Supports feature detection (default), minimum version checks, and live latest-version checks via endoflife.date — use one, two, or all three together.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"uekichinos",
|