Closed wasalm closed 4 months ago
This patch will add two listeners to the event if the webpage is not in code-server. parent.document
exists even in such environments.
Agree, it will create two listeners. However, I don't think this will create an issue because
What will be the value of document
in a code-server env? If undefined
, document ?? parent.document
should work well.
Also it is good to understand why the origional code does work in vscode. The event "webviewerloaded" is only created in viewer.mjs. Here it tries to dispatch this event first in parent.document
and if it fails it dispatches it in document
itself.
The listener for the "webviewerloaded" event is in the file latexworkshop.ts. It shares the same document
with viewer.mjs, because viewer.mjs gets loaded by latexworkshop.ts at line 824. Hence in the origional version, the code will only work if it gets dispatched in document
and not in parent.document
.
For the code-server the parent document and document are on the same origin and hence it is allowed to dispatch events in the parents. I expect that in vscode this will be different and hence when it tries to dispatch in parent, it will give an error.
What will be the value of
document
in a code-server env? Ifundefined
,document ?? parent.document
should work well.
document and parent.document are both well-defined objects, so document ?? parent.document
will not work. the root issue is that pdf.js might send the "webviewerloaded" event to a different iframe than latexworkshop.ts is expecting
Although code-server is not officially supported, hereby a bugfix making (ctrl) + click work in the browser.
Namely, before synctex is enabled, it waits before PDF.js is loaded. PDF.js signals this by sending a custom "webviewloaded" event. It first tries to send it to the parent window and if this fails, it send it to its own window. in code-server, this parent exists as a iframe, hence this event is where there are no listeners. Issue is fixed by added a listener to the parent window if possible.