Glench / ExtPay

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

onPaid.addListener not triggering #71

Closed bluecaret closed 2 years ago

bluecaret commented 2 years ago

Describe the bug I have the following code in my extension to listen to the onPaid event but nothing happens when onPaid should trigger. Following the instructions, I am uninstalling the extension, and "paying" with the development login, but my listener never logs anything. The only thing to happen is ExtPay logging this message: service worker got message! Here it is: fetch-user. I have no idea how to debug this further.

import ExtPay from "extpay";
var extpay = ExtPay("XXXXX");
...
extpay.onPaid.addListener(user => {
  console.log('user paid!', user);
});

Manifest setting:

  "content_scripts": [
    {
      "matches": ["https://extensionpay.com/*"],
      "js": ["lib/ExtPay_content_script.js"],
      "run_at": "document_start"
    }
  ],
  "web_accessible_resources": [
    {
      "resources": [ "assets/material-symbols-outlined.woff2", "assets/logo.svg" ],
      "matches": [ "<all_urls>", "https://extensionpay.com/*" ]
    }
  ],

Per the documentation I added the file lib/ExtPay_content_script.js with the following

import 'ExtPay'

In this file I also tried doing import ExtPay from "extpay"; just in case but same result.

To Reproduce Steps to reproduce the behavior:

  1. Setup the onPaid listener.
  2. Uninstall the extension
  3. Reinstall
  4. Follow dev login to test "paying".
  5. No console log is seen

Expected behavior I'm expecting my console log to show in the open new tab that I triggered the payment in.

Desktop (please complete the following information):

bluecaret commented 2 years ago

I just tested this in production mode as well and still didn't get the response expected.

bluecaret commented 2 years ago

Got it working. Using NPM didn't work, I had to copy ExtPay.js directly into my project despite using rollup. I also had to run the listener in the background script, not the new tab page.