Glench / ExtPay

The JavaScript library for ExtensionPay.com — payments for your browser extensions, no server needed.
https://extensionpay.com
Other
483 stars 62 forks source link

Error in production build #213

Closed rafihaidari closed 2 months ago

rafihaidari commented 3 months ago

Although the extension is not crashing and the ExtPay works, but still I see below error in my build, will it be a problem in future?

As a side note, I am using Plasmo framework for my extension and the permission storage is already added.


You can copy and paste this to your manifest.json file to fix this error:

"permissions": [
    ${t.map(e=>`"    ${e}"`).join(",\n")}${t.length>0?",":""}
    "storage"
]
`}}),a(["extensionpay_installed_at","extensionpay_user"]).then(async e=>{if(e.extensionpay_installed_at)return;let t=e.extensionpay_user,r=t?t.installedAt:new Date().toISOString();await i({extensionpay_installed_at:r})});let s=[],o=[];async function l(){var e,a={};if(n.management)e=await (0,n.management).getSelf();else if(n.runtime){if(!(e=await (0,n.runtime).sendMessage("extpay-extinfo"))){let t=!("update_url"in(0,n.runtime).getManifest());e={installType:t?"development":"normal"}}}else throw"ExtPay needs to be run in a browser extension context";"development"==e.installType&&(a.development=!0);let s=await fetch(`${r}/api/new-key`,{method:"POST",headers:{Accept:"application/json","Content-type":"application/json"},body:JSON.stringify(a)});if(!s.ok)throw s.status,`${t}/home`;let o=await s.json();return await i({extensionpay_api_key:o}),o}async function c(){let e=await a(["extensionpay_api_key"]);return e.extensionpay_api_key?e.extensionpay_api_key:null}let u=/^\d\d\d\d-\d\d-\d\dT/;async function d(){var e=await a(["extensionpay_user","extensionpay_installed_at"]);let t=await c();if(!t)return{paid:!1,paidAt:null,installedAt:e.extensionpay_installed_at?new Date(e.extensionpay_installed_at):new Date,trialStartedAt:null};let n=await fetch(`${r}/api/user?api_key=${t}`,{method:"GET",headers:{Accept:"application/json"}});if(!n.ok)throw"ExtPay error while fetching user: "+await n.text();let l=await n.json(),d={};for(var[h,f]of Object.entries(l))f&&f.match&&f.match(u)&&(f=new Date(f)),d[h]=f;return d.installedAt=new Date(e.extensionpay_installed_at),d.paidAt&&(!e.extensionpay_user||e.extensionpay_user&&!e.extensionpay_user.paidAt)&&s.forEach(e=>e(d)),d.trialStartedAt&&(!e.extensionpay_user||e.extensionpay_user&&!e.extensionpay_user.trialStartedAt)&&o.forEach(e=>e(d)),await i({extensionpay_user:l}),d}async function h(){var e=await c();return e||(e=await l()),`${r}?api_key=${e}`}async function f(e,t,r){if(n.windows&&n.windows.create){let a=await (0,n.windows).getCurrent(),i=Math.round((a.width-t)*.5+a.left),s=Math.round((a.height-r)*.5+a.top);try{(0,n.windows).create({url:e,type:"popup",focused:!0,width:t,height:r,left:i,top:s})}catch(a){(0,n.windows).create({url:e,type:"popup",width:t,height:r,left:i,top:s})}}else window.open(e,null,`toolbar=no,location=no,directories=no,status=no,menubar=no,width=${t},height=${r},left=450`)}var p=!1;async function g(){if(!p){p=!0;for(var e=await d(),t=0;t<120;++t){if(e.paidAt)return p=!1,e;await new Promise(e=>setTimeout(e,1e3)),e=await d()}p=!1}}return{getUser:function(){return d()},onPaid:{addListener:function(e){let r=`"content_scripts": [
                {
            "matches": ["${t}/*"],
            "js": ["ExtPay.js"],
            "run_at": "document_start"
        }]`,a=(0,n.runtime).getManifest();if(!a.content_scripts)throw`ExtPay setup error: To use the onPaid callback handler, please include ExtPay as a content script in your manifest.json. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson

        ${r}`;let i=a.content_scripts.find(e=>e.matches.includes(t.replace(":3000","")+"/*"));if(i){if(!i.run_at||"document_start"!==i.run_at)throw`ExtPay setup error: To use the onPaid callback handler, please make sure the ExtPay content script in your manifest.json runs at document start. You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson

        ${r}`}else throw`ExtPay setup error: To use the onPaid callback handler, please include ExtPay as a content script in your manifest.json matching "${t}/*". You can copy the example below into your manifest.json or check the docs: https://github.com/Glench/ExtPay#2-configure-your-manifestjson
Glench commented 3 months ago

Hey! I'm not sure what the code you pasted is but it seems like something unrelated to ExtPay. Would you be able to recreate a minimal repo demonstrating the issue?

Glench commented 3 months ago

Hey! Just wanted to check in about this! If we don't hear from you soon then we'll close the issue.