Preserving current page number with vscode-pdf

I’m using the VS Code extension vscode-pdf, which under the hood uses PDF.js to render PDF files in a Webview within VS Code. After loading, the extension watches the opened PDF file for changes and if it detects any it reloads the file. This is a great feature, except as reported in a Github issue it causes the PDF view to jump to the top of the file on reload. This is not so great if you’re automatically (re)generating the PDF from for example a Latex document and want to quickly be able to see your changes (which is exactly what I do when editing my fiction writing).

The underlying PDF.js library already handles this, but it relies on detecting the page was reloaded which doesn’t look to be possible with the current VSCode Webview API. Instead I figured it should be possible to grab the current page number, reload the PDF file, and then reset the page number to the previous value. Turns out that did work, and a fix was released in version 1.2.0 of vscode-pdf.

Updated: