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

[Bug] Missing Reader Menu when used with Better BibTeX #231

Closed
2 tasks done
mjthoraval opened this issue Jan 3, 2024 · 19 comments
Closed
2 tasks done

[Bug] Missing Reader Menu when used with Better BibTeX #231

mjthoraval opened this issue Jan 3, 2024 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@mjthoraval
Copy link

mjthoraval commented Jan 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest Zotero and the latest plugin?

  • I have confirmed I'm using the latest Zotero and the latest plugin

Environment

  • OS: Windows 10
  • Zotero Version: 7.0.0-beta.54+6b996d4f9 (64-bit)
  • Plugin Version: 1.0.0-31
  • BBT Version: v6.7.140

Describe the bug

Steps to reproduce with the A&T and BBT plugins:

  1. Open a PDF file in a Zotero PDF Viewer
  2. While looking at the PDF, close and restart Zotero

-> After restarting, the PDF Viewer loads automatically. But the Reader Menu of the plugin is missing.
Closing and reopening the tab fixes the problem, with the Reader Menu appearing again.
Doing the same with the BBT plugin disabled does not produce this issue.

Debug Output

1704295785999 addons.xpi WARN Checking C:\Program Files\Zotero\distribution\extensions for addons

[JavaScript Error: "NS_NOINTERFACE: " {file: "resource://gre/modules/ComponentUtils.jsm" line: 90}]
createInstance@resource://gre/modules/ComponentUtils.jsm:90:36

1704295787417 addons.xpi WARN Addon with ID undefined already installed, older version will be disabled

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1710}]

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1710}]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NS_ERROR_NOT_AVAILABLE" {file: "resource://gre/modules/PartitioningExceptionListService.jsm" line: 92}]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "NotFoundError: Could not get children of file(C:\Users\mjthoraval\AppData\Roaming\Zotero\Zotero\Crash Reports\events) because it does not exist" {file: "resource://gre/modules/CrashManager.jsm" line: 682}]
_getUnprocessedEventsFiles/<@resource://gre/modules/CrashManager.jsm:682:12

appName => Zotero, version => 7.0.0-beta.54+6b996d4f9, os => Windows 10.0 19045, locale => en-US, extensions => Better BibTex for Zotero (6.7.140, extension), Actions and Tags for Zotero (1.0.0-31, extension), Zotero PDF Preview (1.0.0-4, extension, disabled), Zotero Better Authors (4.0.2, extension, disabled), Translate for Zotero (1.1.0-22, extension, disabled), Better Notes for Zotero (1.1.4-49, extension, disabled), Open PDF for Zotero (0.0.10, extension, disabled)

Anything else?

No response

@mjthoraval mjthoraval added the bug Something isn't working label Jan 3, 2024
@windingwind
Copy link
Owner

Could you please report this to the BBT repo as well? Hopefully we can get some hint there

@mjthoraval
Copy link
Author

Done, thank you.

@retorquere
Copy link

Can you serialize the container of that element after that happens? I can indeed reproduce it at will, but even if I remove all my code that scribbles in that area, the problem remains.

@retorquere
Copy link

Oh and it'd be helpful if you could add a mutationobserver to log when it is removed (or hidden?). Maybe what BBT is doing around that point will give us some idea.

@windingwind
Copy link
Owner

Hmm... I am using Zotero.Reader.registerEventListener("renderToolbar", callback) API to create a button in the reader's toolbar, which I guess is...not possibly be broken by BBT or any plugin.

Try the build below: I've added an IntersectionObserver and when the element becomes visible/invisible it will console.log and Zotero.debug reader menu button is (in)visible with the element's parent element. Please let me know if there's more I can help.

zotero-actions-tags.xpi.zip

@windingwind
Copy link
Owner

The relevant code is here, in case you need it:

function initReaderMenu() {
const image =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsSAAALEgHS3X78AAAA40lEQVRYCWP8//8/AyFwJL/hjsbXJ8oEFSKBG9wyd20mNqgQUsdESMGCypkppFoOAiA924s711PsAOmfb2NItRwGWP7/FaTYAbQGow4YdcCoA0YdMOqAUQcMuANYCCm4yS394AWboD05hn9k5XrgSqkDjgloPiDHcih4kENAwWgaGHXAqAModcBFKB4QB4AsdoBish1BrgPAli8rNvsAwpQ4ghwHLIRZDhNAcsRCUg0jWBSjW76s2CwBmwTUEQlRvadA3HhiDSQlBHBajuYQkBqiQ4JYBxQSYzmaIwoJKmRgYAAAgCNBYXH3oBUAAAAASUVORK5CYII=";
const readerButtonCSS = `
.actions-tags-reader-menu::before {
background-image: url(${image});
background-size: 100%;
content: "";
display: inline-block;
height: 16px;
vertical-align: top;
width: 16px;
}
.actions-tags-reader-menu .dropmarker {
background: url(assets/icons/searchbar-dropmarker@2x.4ebeb64c.png) no-repeat 0 0/100%;
display: inline-block;
height: 4px;
margin: 6px 0;
margin-inline-start: 2px;
position: relative;
vertical-align: top;
width: 7px;
z-index: 1;
}
`;
Zotero.Reader.registerEventListener(
"renderToolbar",
(event) => {
const { append, doc } = event;
append(
ztoolkit.UI.createElement(doc, "button", {
namespace: "html",
classList: ["toolbarButton", "actions-tags-reader-menu"],
properties: {
tabIndex: -1,
title: "Actions",
},
listeners: [
{
type: "click",
listener: (ev: Event) => {
document
.querySelector(`#${config.addonRef}-reader-popup`)
// @ts-ignore XUL.MenuPopup
?.openPopup(
doc.querySelector(".actions-tags-reader-menu"),
"after_start",
);
},
},
],
children: [
{
tag: "span",
classList: ["button-background"],
},
{
tag: "span",
classList: ["dropmarker"],
},
],
}),
);
append(
ztoolkit.UI.createElement(doc, "style", {
id: `${config.addonRef}-reader-button`,
properties: {
textContent: readerButtonCSS,
},
}),
);
},
config.addonID,
);
}

@retorquere
Copy link

I have no idea how Zotero.Reader works or how BBT could interfere with it; BBT is not using it. I have replayed the scenario and reader menu button is visible doesn't show up at all in the log after start. It isn't until the tab is closed and reopened that the message appears. If I disable all UI code from BBT entirely, the problem still occurs. Can you put a log statement at the top of your "renderToolbar" listener to verify it isn't being called?

@windingwind
Copy link
Owner

OK, now it shows a log reader renderToolbar called with the callback args.

Could BBT somehow delay or affect the event dispatch on readers?

zotero-actions-tags.xpi.zip

@retorquere
Copy link

I have no idea how it would do that. And then why doesn't that happen on re-open?

Do I understand correctly that this is reached correctly then? What point in the code is not being reached?

@windingwind
Copy link
Owner

OK... I guess perhaps BBT loading somehow delays the loading of other plugins and thus the registration of these callbacks comes after Zotero opens the readers. So this isn't actually a bug with BBT. I'll try to release a fix.

@mjthoraval
Copy link
Author

I have updated BBT to v6.7.143. Then I have tested to see if the problem was still there. But I could not reproduce anymore...
Then I went back to v6.7.140 to double check that the problem was fixed by the update. But I still could not reproduce anymore with exactly the same configuration as before...

Are you both able to reproduce?
Also with v6.7.143?
Any idea on what could have changed and how I could trigger the problem again to understand it?
The steps to reproduce are really simple, and you confirmed that you could reproduce, so it is not only something wrong on my side...

@retorquere
Copy link

If it's indeed a timing issue it could well be that the installation order plays a role.

@mjthoraval
Copy link
Author

Exactly!
I have reinstalled A&T and got the problem again.
So the installation order in Zotero is actually important... Is that something normal?

@mjthoraval
Copy link
Author

Is there any way to overwrite the order imposed by the installation order?

@retorquere
Copy link

Exactly!
I have reinstalled A&T and got the problem again.
So the installation order in Zotero is actually important... Is that something normal?

I think it's not entirely avoidable given how bootstrapped plugins work.

@retorquere
Copy link

Is there any way to overwrite the order imposed by the installation order?

Probably, yes, but that's just kicking the problem down the road.

@windingwind
Copy link
Owner

OK I've released a new beta, hope it works

@windingwind
Copy link
Owner

Not sure but this could be possibly fixed in the Zotero side's API. I will notify the team

@mjthoraval
Copy link
Author

I confirm that it is fixed.
Thank you very much both of you!

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

No branches or pull requests

3 participants