How to Click on Chrome Extension "Button"



Hello,

Printing is always a problem with Chrome, and this is solved by the superb Chrome extension Print Friendly & PDF.

The extension web site:
Print Friendly & PDF - Chrome Web Store

I want to create a macro to print to PDF → download that I can trigger every time I visit a web site (usually an article) I want to "print" (save as PDF).

Everything works perfectly: I trigger the extension → using KM, I press the PDF button.

I am unable to:

  1. Trigger Extension Print Friendly & PDF using the native keyboard shortcut.

  2. Click on PDF which works with the KM action click on button "PDF".
     

  3. Where I am stuck: at the next and final step, I have to click on the green "Download You PDF" button.

The following does not work. Note that the button has the following link:

https://pdf.printfriendly.com/downloads/pdf_1679050850_34ba79A4.pdf

Obviously, I do not work the _1679050850_34ba79A4.pdf part of the URL which is specific for a single site

  1. Click on button KM action
  2. Click on Chrome Link action
  3. Click on found image - I tried all degrees of "e"
  4. The Chrome inspector shows as per the ScreenShot below, but I don't know how I would use it

Thanks in advance for your time and help.

image

Image detection is working for me, with the default action settings. Have you included a "Pause until..." that image is visible, to account for the PDF's preparation time?

For better JavaScripters than me -- it's a link rather than a button. This is the code when the download is ready:

<a class="btn btn-pf btn-xl btn-success js-pdf-download pdf-download" href="https://pdf.printfriendly.com/downloads/pdf_1679054582_599fc4A4.pdf" target="">
<!-- unnecessary SVG data etc snipped -->
</a>

...and I guess could you target the element via its classes (though I have no idea how!).

Thanks very much for giving my problem some thought, and all your efforts.

The macro does not work.

KM Engine LOG does not recognize pdf_1679054582_599fc4A4.pdf which makes sense because it is web site specific, ie the web site you used when you tested the shell script.

How could I convert that portion of the shell script into a generic format?

Thanks very much.

The code snippet I posted is (part of) the HTML code for the "Download" link -- the span bit you gave just formats the text, and (probably) can't be used as the element identifier. Someone who knows JavaScript (which isn't me!) might be able to use those listed classes to identify and "click" the download link.

Can you upload a sample macro of your step 2 "click on PDF" through to the "click on found image, which isn't working". As I said, the image worked fine for me on Safari -- if I can compare yours and mine I might be able to come up with something.

1 Like

Thank you for your explanations.

Macro attached.

The ideal solution seems to to simply use the press button action which works for the initial PDF button.

image

The question is how would you call the following button in the press button action.
The problem is the image preceeding Download Your PDF.

The 10 second pause is not necessary. Just to show that it is not a question of too short a pause.

Thank you.

ZZ Test Print Download PDF.kmmacros (29.3 KB)

I wouldn't -- that whole area is "active", so use it all (just in case there's a clash with the smaller part from something else on your screen). This was working for me, albeit in Safari, with "Click at (0,0) relative to found image's center":

image

1 Like

I will try again. thank you.

I tried to install the extension in safari but encountered an error message and am waiting to hear back from the developer.

Thanks again.

image

I was just opening the site (https://pdf.printfriendly.com) and using the form there -- I daresay the plug-in just automates that bit, submitting the form info directly.

But you should be able to do this directly with KM:

Open Front Safari Tab as PDF.kmactions (853 Bytes)

image

Edit to add:
Indeed, this is working in Safari for me (and even includes clicking the "Allow downloads" button if needed):

Get PDF Complete.kmmacros (145.1 KB)

Image

Hey Guys,

I installed the extension in Google Chrome 111.0.5563.64 on macOS 10.14.6.

I was able to give it a keyboard shortcut, and the shortcut works with no problems.

image


These work when run from the Dev-Tools in Chrome, but Chrome-Extensions are sandboxed – and these won't work when run via Apple Events (ergo KM's JavaScript actions or AppleScript).

Print to PDF Button Ref:

document.querySelector("#pdf").click()

Download your PDF Button Ref:

document.querySelector("#pf-dialog-pdf > div > div:nth-child(1) > a > span").click()

The upshot of this is that you may think after testing in the browser that the JavaScript will work in Keyboard Maestro, but you'd be wrong. Several people have pulled their hair out because of this...


-Chris

3 Likes

Hello @ccstone and @Nige_S

@Nige_S thank you very much for your macro which works perfectly in safari.

In Chrome, I am back to square one. None of the found image actions worked, exactly as they did not work for me. It does not make sense but I tested a million times and variants. Exactly as per my initial post.
As per my initial post

  • in chrome I can simply use the press button action for PDF
  • the only step remaining is to press the last download button. Nothing works.

question for Chris

How would I use this information in a KM action ? what would I write in the field below or would I use another action ?

If it's not possible, is there any way to use the fact that the download button has a striking green color ?

thanks very much to both of you

You're probably running into the perennial front window problem in Google Chrome.

1 Like

OK. thanks very much.

In the meantime, I am using maximize window → triple click at absolute position which usually works.

Last question and I shall leave you in peace: I notice that long press is the most reliable way to click on download. As a substitute I am using triple click. Is there any way to long press at given location ?

Thank you

Sorry. I had not understood.

You're probably better off using the work-around for found image in Chrome I provided in the linked post.

Chris,

IIRC you used to be able to put JavaScript snippets in the browser Favorites bar (bookmarklets?). Do those suffer from the same sandboxing restrictions? Could that be a possible approach to this problem (it looks like everything's constant, so no variable passing from KM etc)?

Hey Nige,

That's a great out-of-the-box thought.

I had a go at a bookmarklet and couldn’t get it working in this context, but I don't really know what I'm doing there...

-Chris

If you don't, I've got no chance...

Paging @ComplexPoint! Guru to Thread 3, please!

1 Like

Mmm... not really a user of Chrome extensions,
and my assumption has always been that their evaluation space is deliberately inaccessible from that of the browser's document display tabs.

2 Likes

I've done a little more testing, and I'm all but certain my failure with the print button was due to sandboxing and not my own mistakes.

I thought there might be a sliver of a chance that a JavaScript bookmarklet could bridge the sandboxing between document and extension, but I've proven to my own satisfaction that this is not the case.

4 Likes