Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{{url}} and {{title}} is undefined #15

Closed
jinliu opened this issue Apr 15, 2023 · 5 comments
Closed

{{url}} and {{title}} is undefined #15

jinliu opened this issue Apr 15, 2023 · 5 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers Priority A

Comments

@jinliu
Copy link

jinliu commented Apr 15, 2023

Describe the bug
Clicking on the quick capture icon often results in {{url}} and {{title}} expands to 'undefined'.

To Reproduce
Steps to reproduce the behavior:

  1. Open Firefox or Vivaldi.
  2. Open a new tab and go to some website.
  3. Select some text and click on the quick capture popup.
  4. Switch to logseq and check the capture.
  5. Note: Url and title are 'undefined'
  6. Now switch to the browser
  7. Click on the logseq copilot extension icon on the toolbar.
  8. Now quick capture again.
  9. Note: Url and title filled.

Expected behavior
Url and title always filled.

Desktop (please complete the following information):

  • OS: archlinux
  • Browser: Firefox 112.0, Vivaldi 5.7.2921.65

Additional context
This can be fixed by adding 'tabs' permission to manifest.json.
As explained in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions
you need this permission for tabs.url and tabs.title.

And as in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission
you can read the url and title of the active tab, but only after the user clicks the extension icon.

@EINDEX EINDEX self-assigned this Apr 18, 2023
@EINDEX EINDEX added bug Something isn't working Priority A labels Apr 18, 2023
@EINDEX
Copy link
Owner

EINDEX commented Apr 18, 2023

This is interesting, I never thought that Behaver will have differences between Chrome and Firefox.

And, Thanks for sharing this.

Setting this as top priority, will fix it soon.

@EINDEX EINDEX added the good first issue Good for newcomers label Apr 18, 2023
@jinliu
Copy link
Author

jinliu commented Apr 18, 2023

This is interesting, I never thought that Behaver will have differences between Chrome and Firefox.

Perhaps not Chrome vs. Firefox, since Vivaldi is using Chrome extension store, and also has the problem.
And I tried a fresh install of Chrome (v112.0.5615.121), has the same problem.

Both can be fixed by adding the "tabs" permission, or even better, by explicitly requesting <all_urls> host permission:
Chrome:
"host_permissions": [ "<all_urls>" ],
Firefox:

"permissions": [
    "<all_urls>",
    "storage",
    "activeTab",
    "contextMenus"
  ],

Since we already requested content_scripts on <all_urls>, this way we requests one less permission from user.

This is a bit weird, since I thought content_scripts implies host_permission, but seems not in my PC.

BTW, the Chrome manifest file seems to have some rendering bug in <all_urls>:

   "content_scripts": [ {
      "css": [ "content-script.css" ],
      "js": [ "content-script.js" ],
      "matches": [ "http://*/*", "https://*/*", "\u003Call_urls>" ]
   } ],

@EINDEX
Copy link
Owner

EINDEX commented Apr 18, 2023

Interesting, I was try chrome and Firefox on my machine, both working fine.

I don't want to bring unnecessary permission to users, but content_scripts is same as host_permissions when doing the store review.

My OS is macOS 13.2.1(22D68)

Below is the manifest I am using on Firefox Version 112.0.5615.121 (Official Build) (arm64).

{
  "version": "1.10.11",
  "author": "eindex.lee@gmail.com",
  "name": "Logseq Copilot",
  "description": "Logseq Copilot, Connect with you logseq API server, bring your information when you browsing.",
  "chrome_url_overrides": {},
  "icons": {
    "192": "assets/img/logo-192.png"
  },
  "content_scripts": [
    {
      "matches": [
        "http://*/*",
        "https://*/*",
        "<all_urls>"
      ],
      "js": [
        "content-script.js"
      ],
      "css": [
        "content-script.css"
      ]
    }
  ],
  "permissions": [
    "storage",
    "activeTab",
    "contextMenus"
  ],
  "options_ui": {
    "page": "options.html",
    "browser_style": false,
    "open_in_tab": true
  },
  "manifest_version": 2,
  "background": {
    "scripts": [
      "background.js"
    ]
  },
  "web_accessible_resources": [
    "content-script.css",
    "assets/img/logo.png"
  ],
  "browser_action": {
    "default_popup": "popup.html",
    "default_title": "Logseq Copilot"
  },
  "browser_specific_settings": {
    "gecko": {
      "id": "{dbe73d0a-f6b8-474a-ad39-0d46a07e4525}"
    }
  }
}

And this for Chrome Version 112.0.5615.121 (Official Build) (arm64):

{"version":"1.10.16","author":"eindex.lee@gmail.com","name":"Logseq Copilot","description":"Logseq Copilot, Connect with you logseq API server, bring your information when you browsing.","chrome_url_overrides":{},"icons":{"192":"assets/img/logo-192.png"},

"content_scripts":[{"matches":["http://*/*","https://*/*","<all_urls>"],
"js":["content-script.js"],
"css":["content-script.css"]}],
"permissions":["storage","activeTab","contextMenus"],

"options_ui":{"page":"options.html","browser_style":false,"open_in_tab":true},"manifest_version":3,"key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnkAYeXnTWrNIu2h8D4xi9NHWLe0eTR3CX8DDw1c0qyCucaCKxkk/+gZcl89Ifyq5joXc/CeQrM3QVjrL1RAXrKZVqTNvBCUh1H1oJJ47nqkKKI6bNZVT8utjFTjDD1ZYXPYzQhsGuP/cY1wIrlhhIuawFW1h+UUwYlYQtS5FcjJ/RPrao+8KwJaS9p3Cei9rWXhE/PV19ZVOqOUx9ZSzj5/OYCB1u1VWFD5BlUbTXSbzyM/VvXZseAVruVy7oRHJ565AH/uPz2ZVL55Gz0LzcHw4HNRc2f+mSVAbHAuK7JDWtRlrZ3Fbav9qBrcVIAxTpnf5B2I2YMBMcu852Vkc3QIDAQAB","background":{"service_worker":"background.js"},"web_accessible_resources":[{"resources":["content-script.css","assets/img/logo.png"],"matches":[]}],"action":{"default_popup":"popup.html","default_title":"Logseq Copilot"}}

EINDEX added a commit that referenced this issue Apr 18, 2023
Signed-off-by: EINDEX <snowstarlbk@gmail.com>
@jinliu
Copy link
Author

jinliu commented Apr 18, 2023

You are actually not requesting any additional permissions by using host_permissions, since you already requested "Access your data for all websites" with context_scripts.

Anyway, this is very weird since we are using the same browser versions, the only difference seems to be Mac vs Linux. Maybe we close this issue for now (until someone else encounters the same problem)? I can do with using the right-click menu (it works) instead of the floating button to capture.

@jinliu jinliu closed this as completed Apr 19, 2023
@EINDEX
Copy link
Owner

EINDEX commented Apr 19, 2023

I add permission back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Priority A
Projects
None yet
Development

No branches or pull requests

2 participants