Setting watermark for download only

I’m trying to add a watermark before the file is downloaded and then remove the watermark.
It worked yesterday, and today, for some reason, the watermark isn’t removed after the download.

my code looks like this:

window.webviewerFunctions = {
  initWebViewer: function () {
      const viewerElement = document.getElementById( 'viewer' );
      WebViewer( {
          path: 'lib'
      }, viewerElement ).then( ( instance ) => {
            const { docViewer } = instance;
            const { annotationManager, documentViewer, Tools, Core } = instance.Core;

            document.querySelectorAll( '.download-file-button' )
                .forEach( input => input.addEventListener( 'click', async ( e ) => {
                    documentViewer.setWatermark( {
                        diagonal: {
                            fontSize: 40,
                            fontFamily: 'sans-serif',
                            fontWeight: 'bold',
                            color: '#00a0df',
                            opacity: 25,
                            text: 'test'
                        }
                    } );
                    await instance.UI
                        .downloadPdf( { includeAnnotations: !!e.target.getAttribute( 'data-include-annotations' ) } )
                        .then( () => documentViewer.setWatermark( { diagonal: { text: '' } } ) );
                } ) );
      } )
  }
};

Hello Sebastien, thank you for joining the PDFTron community forum.

So your requirement is to allow a user to download PDF from WebViewer and the downloaded PDF should have your custom watermarks is it correct?

Have you used this guide PDFTron Systems Inc. | Documentation?
And if it worked before did something change afterward?

Yes that is correct, and yes indeed I have tried this guide to create the watermark.
The creation of the watermark works fine, on pdf, word or excel documents, not on pictures (jpg). But after the file gets downloaded, the watermark is
present in the web viewer although I programmatically remove it.
I haven’t changed anything since yesterday, sometimes it works, sometimes it doesn’t. If I put a breakpoint in the code and go line by line, it seems to work. I have tried with and without await, with some setTimeout(), but I don’t seem to be getting the final result I want :frowning: