@strivacity/sdk-core 2.2.0 → 3.0.0-rc.0
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 +27 -0
- package/README.md +6 -2
- package/dist/flows/BaseFlow.cjs.map +1 -1
- package/dist/flows/BaseFlow.d.ts +1 -1
- package/dist/flows/BaseFlow.mjs.map +1 -1
- package/dist/flows/EmbeddedFlow.cjs +2 -0
- package/dist/flows/EmbeddedFlow.cjs.map +1 -0
- package/dist/flows/EmbeddedFlow.d.ts +25 -0
- package/dist/flows/EmbeddedFlow.mjs +2 -0
- package/dist/flows/EmbeddedFlow.mjs.map +1 -0
- package/dist/flows/NativeFlow.cjs +1 -1
- package/dist/flows/NativeFlow.cjs.map +1 -1
- package/dist/flows/NativeFlow.d.ts +1 -1
- package/dist/flows/NativeFlow.mjs +1 -1
- package/dist/flows/NativeFlow.mjs.map +1 -1
- package/dist/flows/PopupFlow.cjs +1 -1
- package/dist/flows/PopupFlow.cjs.map +1 -1
- package/dist/flows/PopupFlow.mjs +1 -1
- package/dist/flows/PopupFlow.mjs.map +1 -1
- package/dist/flows/RedirectFlow.cjs +1 -1
- package/dist/flows/RedirectFlow.cjs.map +1 -1
- package/dist/flows/RedirectFlow.mjs +1 -1
- package/dist/flows/RedirectFlow.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +42 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/EmbeddedFlowHandler.cjs +2 -0
- package/dist/utils/EmbeddedFlowHandler.cjs.map +1 -0
- package/dist/utils/EmbeddedFlowHandler.d.ts +61 -0
- package/dist/utils/EmbeddedFlowHandler.mjs +2 -0
- package/dist/utils/EmbeddedFlowHandler.mjs.map +1 -0
- package/dist/utils/NativeFlowHandler.cjs +1 -1
- package/dist/utils/NativeFlowHandler.cjs.map +1 -1
- package/dist/utils/NativeFlowHandler.d.ts +1 -1
- package/dist/utils/NativeFlowHandler.mjs +1 -1
- package/dist/utils/NativeFlowHandler.mjs.map +1 -1
- package/dist/utils/errors.cjs +1 -1
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.ts +12 -0
- package/dist/utils/errors.mjs +1 -1
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/handlers.cjs +1 -1
- package/dist/utils/handlers.cjs.map +1 -1
- package/dist/utils/handlers.d.ts +2 -1
- package/dist/utils/handlers.mjs +1 -1
- package/dist/utils/handlers.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.cjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(
|
|
1
|
+
{"version":3,"file":"handlers.cjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\nimport { PopupBlockedError, PopupClosedError } from './errors';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(\n\tpopupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>),\n\tparams?: PopupParams,\n): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new PopupBlockedError();\n\t}\n\n\tpopupWindow.focus();\n\n\tif (typeof popupHandlerOrUrl === 'function') {\n\t\tawait popupHandlerOrUrl(popupWindow);\n\t} else {\n\t\tpopupWindow.location.replace(popupHandlerOrUrl);\n\t}\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif ((!params?.checkOrigin || event.origin === window.location.origin) && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(new PopupClosedError());\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","responseMode","data","popupUrlHandler","popupHandlerOrUrl","disposables","closeWindow","dispose","popupWindowFeatures","width","value","key","PopupBlockedError","reject","listener","event","timer","PopupClosedError","popupCallbackHandler","_url","args"],"mappings":"gHAGA,IAAIA,EAAkC,KAStC,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 @@ declare function redirectCallbackHandler(url?: string, responseMode?: ResponseMo
|
|
|
20
20
|
*
|
|
21
21
|
* @param {string} url The URL to redirect to in the popup.
|
|
22
22
|
* @param {PopupParams} [params] Optional parameters for the popup, including window features and target.
|
|
23
|
+
* @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.
|
|
23
24
|
* @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.
|
|
24
25
|
* @throws {Error} If the popup window is blocked or closed by the user.
|
|
25
26
|
*/
|
|
26
|
-
declare function popupUrlHandler(
|
|
27
|
+
declare function popupUrlHandler(popupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>), params?: PopupParams): Promise<Record<string, string>>;
|
|
27
28
|
/**
|
|
28
29
|
* Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.
|
|
29
30
|
*
|
package/dist/utils/handlers.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let n=null;async function
|
|
1
|
+
import{PopupBlockedError as h,PopupClosedError as f}from"./errors.mjs";let n=null;async function u(r,i){const e=i?.targetWindow==="top"?window.top:window.self,a=i?.locationMethod||"assign";return e&&e.location[a](r),new Promise(o=>o())}function g(r=globalThis.window?.location.href,i){const e=new URL(r)[i==="query"?"search":"hash"].slice(1);return Promise.resolve(Object.fromEntries(new URLSearchParams(e)))}async function m(r,i){const e=new Set,a=()=>{n&&(n.closed||n.close(),n=null);for(const t of e)t();e.clear()};n&&a();const o={location:!1,toolbar:!1,height:640,...i?.popupWindowFeatures};if(o.width===void 0&&(o.width=[800,720,600,480].find(t=>t<=window.outerWidth/1.618)??360),o.left=Math.max(0,Math.round(window.screenX+(window.outerWidth-o.width)/2)),o.height!==void 0&&(o.top=Math.max(0,Math.round(window.screenY+(window.outerHeight-o.height)/2))),n=window.open(void 0,i?.popupWindowTarget||"_blank",Object.entries(o).filter(([,t])=>t!==null).map(([t,s])=>`${t}=${typeof s!="boolean"?s:s?"yes":"no"}`).join(",")),!n)throw new h;n.focus(),typeof r=="function"?await r(n):n.location.replace(r);const w=await new Promise((t,s)=>{const d=c=>{(!i?.checkOrigin||c.origin===window.location.origin)&&c.source===n&&c.data&&t(c.data)},l=setInterval(()=>{n?.closed&&(clearInterval(l),s(new f))},500);window.addEventListener("message",d),e.add(()=>window.removeEventListener("message",d)),e.add(()=>clearInterval(l))});return a(),w}function b(r,i){const e={};return i==="fragment"?new URLSearchParams(globalThis.window?.location.hash.replace("#","?")).forEach((a,o)=>e[o]=a):new URLSearchParams(globalThis.window?.location.search).forEach((a,o)=>e[o]=a),globalThis.window?.opener?.postMessage(e,"*"),new Promise(()=>{})}export{b as popupCallbackHandler,m as popupUrlHandler,g as redirectCallbackHandler,u as redirectUrlHandler};
|
|
2
2
|
//# sourceMappingURL=handlers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.mjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(
|
|
1
|
+
{"version":3,"file":"handlers.mjs","sources":["../../src/utils/handlers.ts"],"sourcesContent":["import type { RedirectParams, ResponseMode, PopupParams, PopupWindowFeatures } from '../types';\nimport { PopupBlockedError, PopupClosedError } from './errors';\n\nlet popupWindow: WindowProxy | null = null;\n\n/**\n * Handles URL redirection to a target window using a specified location method.\n *\n * @param {string} url The URL to redirect to.\n * @param {RedirectParams} [params] Optional parameters for the redirection, including the target window and location method.\n * @returns {Promise<void>} A promise that resolves when the redirection occurs.\n */\nasync function redirectUrlHandler(url: string, params?: RedirectParams): Promise<void> {\n\tconst targetWindow = params?.targetWindow === 'top' ? window.top : window.self;\n\tconst method = params?.locationMethod || 'assign';\n\n\tif (targetWindow) {\n\t\ttargetWindow.location[method](url);\n\t}\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise((resolve) => resolve());\n}\n\n/**\n * Handles the callback after a redirect and parses the response from the URL.\n *\n * @param {string} [url=globalThis.window?.location.href] The URL to parse, defaults to the current window location.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the parsed response data.\n */\nfunction redirectCallbackHandler(url: string = globalThis.window?.location.href, responseMode?: ResponseMode): Promise<Record<string, string>> {\n\tconst data = new URL(url)[responseMode === 'query' ? 'search' : 'hash'].slice(1);\n\n\treturn Promise.resolve(Object.fromEntries(new URLSearchParams(data)));\n}\n\n/**\n * Opens a popup window to handle URL redirection and resolves with the data received from the popup.\n *\n * @param {string} url The URL to redirect to in the popup.\n * @param {PopupParams} [params] Optional parameters for the popup, including window features and target.\n * @param {{ checkOrigin: boolean }} [options] Optional settings for the popup handler.\n * @returns {Promise<Record<string, string>>} A promise that resolves to the data received from the popup window.\n * @throws {Error} If the popup window is blocked or closed by the user.\n */\nasync function popupUrlHandler(\n\tpopupHandlerOrUrl: string | ((popupWindow: Window) => void | Promise<void>),\n\tparams?: PopupParams,\n): Promise<Record<string, string>> {\n\tconst disposables = new Set<() => void>();\n\tconst closeWindow = (): void => {\n\t\tif (popupWindow) {\n\t\t\tif (!popupWindow.closed) {\n\t\t\t\tpopupWindow.close();\n\t\t\t}\n\n\t\t\tpopupWindow = null;\n\t\t}\n\n\t\tfor (const dispose of disposables) {\n\t\t\tdispose();\n\t\t}\n\n\t\tdisposables.clear();\n\t};\n\n\tif (popupWindow) {\n\t\tcloseWindow();\n\t}\n\n\tconst popupWindowFeatures: PopupWindowFeatures = {\n\t\tlocation: false,\n\t\ttoolbar: false,\n\t\theight: 640,\n\t\t...params?.popupWindowFeatures,\n\t};\n\n\tif (popupWindowFeatures.width === undefined) {\n\t\tpopupWindowFeatures.width = [800, 720, 600, 480].find((width) => width <= window.outerWidth / 1.618) ?? 360;\n\t}\n\n\tpopupWindowFeatures.left = Math.max(0, Math.round(window.screenX + (window.outerWidth - popupWindowFeatures.width) / 2));\n\n\tif (popupWindowFeatures.height !== undefined) {\n\t\tpopupWindowFeatures.top = Math.max(0, Math.round(window.screenY + (window.outerHeight - popupWindowFeatures.height) / 2));\n\t}\n\n\tpopupWindow = window.open(\n\t\tundefined,\n\t\tparams?.popupWindowTarget || '_blank',\n\t\tObject.entries(popupWindowFeatures)\n\t\t\t.filter(([, value]) => value !== null)\n\t\t\t.map(([key, value]) => `${key}=${typeof value !== 'boolean' ? (value as string) : value ? 'yes' : 'no'}`)\n\t\t\t.join(','),\n\t);\n\n\tif (!popupWindow) {\n\t\tthrow new PopupBlockedError();\n\t}\n\n\tpopupWindow.focus();\n\n\tif (typeof popupHandlerOrUrl === 'function') {\n\t\tawait popupHandlerOrUrl(popupWindow);\n\t} else {\n\t\tpopupWindow.location.replace(popupHandlerOrUrl);\n\t}\n\n\tconst data = await new Promise<Record<string, string>>((resolve, reject) => {\n\t\tconst listener = (event: MessageEvent<Record<string, string>>) => {\n\t\t\tif ((!params?.checkOrigin || event.origin === window.location.origin) && event.source === popupWindow && event.data) {\n\t\t\t\tresolve(event.data);\n\t\t\t}\n\t\t};\n\n\t\tconst timer = setInterval(() => {\n\t\t\tif (popupWindow?.closed) {\n\t\t\t\tclearInterval(timer);\n\t\t\t\treject(new PopupClosedError());\n\t\t\t}\n\t\t}, 500);\n\n\t\twindow.addEventListener('message', listener);\n\t\tdisposables.add(() => window.removeEventListener('message', listener));\n\t\tdisposables.add(() => clearInterval(timer));\n\t});\n\n\tcloseWindow();\n\n\treturn data;\n}\n\n/**\n * Handles the callback from a popup window, parsing the response parameters from the URL and posting them to the opener window.\n *\n * @param {string} [_url] the URL is not used in this function, but it is kept for type compatibility.\n * @param {ResponseMode} responseMode The response mode, either 'query' or 'fragment'.\n */\nfunction popupCallbackHandler(_url?: string, responseMode?: ResponseMode): Promise<void> {\n\tconst args: Record<string, string> = {};\n\n\tif (responseMode === 'fragment') {\n\t\tnew URLSearchParams(globalThis.window?.location.hash.replace('#', '?')).forEach((value, key) => (args[key] = value));\n\t} else {\n\t\tnew URLSearchParams(globalThis.window?.location.search).forEach((value, key) => (args[key] = value));\n\t}\n\n\tglobalThis.window?.opener?.postMessage(args, '*');\n\n\t// NOTE: Wait for the previous action\n\treturn new Promise(() => undefined);\n}\n\nexport { redirectUrlHandler, redirectCallbackHandler, popupUrlHandler, popupCallbackHandler };\n"],"names":["popupWindow","redirectUrlHandler","url","params","targetWindow","method","resolve","redirectCallbackHandler","responseMode","data","popupUrlHandler","popupHandlerOrUrl","disposables","closeWindow","dispose","popupWindowFeatures","width","value","key","PopupBlockedError","reject","listener","event","timer","Popup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