DEV Community

Cover image for Automate Adding CVS Coupons
Nazmuz Shakib Pranto
Nazmuz Shakib Pranto

Posted on • Edited on

Automate Adding CVS Coupons

Background (feel free to skip)

Ok, I understand this post is kind of weird OR may not relate to everybody, but stick with me here... let me explain.

I am a Software Engineer by day and as part of my profession, I like to program or code to automate any repeatable tasks that I have to do regularly.

This is where CVS coupons come into play. I generally find myself shopping at CVS Pharmacy often and they have a program called ExtraCare. It sends you, the customer, coupons on a daily or weekly basis to show appreciation and help you to save a few dollars here and there.

Note: CVS did not pay me to write this post, I just found this useful and thought maybe, just maybe, others might find it useful.

Anyways, let's get started.

With this guide, you will no longer have to manually click on each β€œSend to Card” button to auto add ExtraCare coupons for your CVS account.


Who is this for?

If all of these conditions apply to you, you might find this automation useful:

  • Are you a regular customer of CVS Pharmacy?
  • Do you have ExtraCare with CVS and use coupons regularly?
  • Do you hate having to manually add coupons every day or week?

Let's Get Started

Step 1

Open Google Chrome browser, go over to https://www.cvs.com/

CVS Pharmacy - Home

Step 2

Log into your CVS account

CVS Pharmacy - Login

Step 3

Once logged in, click on the "ExtraCare" link from the top navigation bar

ExtraCare Link

Step 4

Now, you should be able to see all of your coupons provided through ExtraCare (specifically for you). There are a lot of coupons here and having to manually add each one of these is a pain. THIS is the part we want to automate!

All CVS Coupons

Step 5

First thing we want to do is scroll down to the bottom of the page. Notice, more and more coupons are being loaded as you scroll to the bottom. Keep scrolling until no more coupons are loaded.

Bottom of Coupons Page

Step 6

Ok, now, right click on anywhere on the page and click on "Inspect" from the menu

Chrome Inspecter

Step 7

This will open up a whole new section on the right side or the bottom of the page.

Chrome DevTools Opens

Step 8

Inside the sidebar, click on "Console" from the top menu

Console in Chrome DevTools

Step 9

Now, copy over this piece of code and paste it right after the > sign

(function run() {
    const coupons = Array.from(document.querySelectorAll('send-to-card-action'))
        .map(e => e.querySelector('.coupon-container .coupon-action.sc-send-to-card-action'))
        .filter(Boolean);

    const totalCoupons = coupons.length;
    console.log(`πŸ›οΈ Total coupons to add: ${totalCoupons}`);

    coupons.forEach((e, index) => {
        setTimeout(() => {
            e.click();
            const couponsLeft = totalCoupons - index - 1;
            console.log(`✨ Coupon added... ${couponsLeft} more left! ✨`);
            if (couponsLeft === 0) {
                console.log("πŸŽ‰ All coupons have been added to your card. Enjoy your savings! πŸŽ‰");
            }
        }, index * 350);
    });

    if (totalCoupons === 0) {
        console.log("πŸŽ‰ All coupons have been added to your card. Enjoy your savings! πŸŽ‰");
    }
})();
Enter fullscreen mode Exit fullscreen mode

Step 10

Then, press ENTER and watch some magic happen in the background. Notice all the coupons being automatically clicked and added for you.
Coupons Script

Step 11

You should see a "Coupons left" counter on the sidebar, it tracks the number of coupons still to be added. Wait until that counter goes all the way down to 0.

Coupons Left Counter

Step 12

That's it, now all the coupons should be added to your account.


Now, I understand that this is clearly not a fully automated system, but it should at least help you avoid having to click on more than 100+ coupons on a regular basis. Let me know if you found this helpful at all. I am planning to build on top of this automation to not have to manually follow all these 12 steps, so hopefully, then, it would be even simpler.

Top comments (19)

Collapse
 
npranto profile image
Nazmuz Shakib Pranto

UPDATE:

It has come to my attention that the previous script no longer works b/c of certain changes to elements in the DOM. So, I have updated the script now. Please feel free to use the latest changes as I hope it should work with recent changes to the UI on the site.

Please let me know if I have missed any weird edge cases or if the script doesn't work for any reason. Thanks!

Collapse
 
jdeen profile image
James Dean

Thanks for the quick update. This script is so useful

Collapse
 
wildcentury501 profile image
Brian McKnight

Thank you! works great!

Collapse
 
cuser profile image
C

Oh no...it's not working for me again. :(

Collapse
 
hellosurbhi profile image
Surbhi

king

Collapse
 
brandenbedoya profile image
Branden Bedoya

This works awesome!! Is there any way to get this to run periodically, like every week? Ideally I don't want to have to pay for a tool like Zapier to do so

Collapse
 
madmaxlax profile image
Max Struever

to automate this a bit more, you can add this as a 'bookmarklet'

where you add this a clickable bookmark, and you dont need to go into inspector and console and copy and paste code.

freecodecamp.org/news/what-are-boo...

Collapse
 
thetimbuk profile image
M.Andersson

This thread was SUPER helpful. Make sure to minify the js code for a functional bookmarklet. I used minify-js.com/ and this output works fine in chrome:
javascript: !function(){const o=[...document.querySelectorAll("send-to-card-action")].map((o=>o?.querySelector(".coupon-container .coupon-action.button-red"))).filter((o=>null!==o));let e=o.length;var t,n;o.forEach((t=o=>{o.click(),console.log(Coupons left: ${e}),e-=1},n=150,(o,e)=>{setTimeout((()=>{t(o)}),e*n)}))}();

Collapse
 
npranto profile image
Nazmuz Shakib Pranto

If anyone else knows of any other sites that might require similar automation to auto-add coupons to cards, I would love to know more about it, so I can contribute to fixing those as well. Let me know, ty!

Collapse
 
cuser profile image
C

Shoprite! :)

Collapse
 
tigeruppercut profile image
Tony Jackson

Second for Shoprite

Collapse
 
christy_hagood_dd0909912b profile image
Christy Hagood

THANK YOU! THANK YOU! THANK YOU! This was amazing and SO EASY to do. Saving me a ton of time.

Collapse
 
wildcentury501 profile image
Brian McKnight

Hey it seems like the script is no longer working as of today. Its returning "undefined". Last time it worked was 4 days ago for me. I guess they made changes to the website, hopefully just some updates and not something to block the automation.

Collapse
 
hellosurbhi profile image
Surbhi

Hey Nazmuz, this recently stopped working unfortunately

Collapse
 
wildcentury501 profile image
Brian McKnight

I wonder if it was deliberate.

Collapse
 
cuser profile image
C

Any chance you'd consider doing this for Shoprite? They just went all digital with their coupons, too. Same format. Takes forever to load each individual coupon to your card on their app.

Collapse
 
zedx12345 profile image
Must

Thanks a lot, this works wonderfully!

Collapse
 
tigeruppercut profile image
Tony Jackson

This is absolutely amazing. I was just looking online to see if this was possible. Thanks alot

Collapse
 
cuser profile image
C

Can't thank you enough for this. Just an FYI, today I had to paste and return about 5 or 6 times to get all the coupons to copy. Not a problem at all, but just letting you know. THANK YOU again! :)