Runs: Every hour

Get an email when something is back in stock

Stop refreshing a sold-out product page. A bot checks it every hour and emails you the moment it can be bought again.

Refreshing a sold-out page every morning is a chore a bot does better. This one reads the page every hour, notices when the shop starts offering it again, and sends you one email at that moment, not one every hour.

  1. Find the words that change

    Open the product page. Find text that only shows up when the item is available, such as Add to cart, or only when it isn't, such as Out of stock.

    Now check the shop sends that text in the page itself: right-click the page, choose View page source, and search for it with Ctrl+F (Cmd+F on a Mac). If it isn't there, the shop builds the page with JavaScript and this simple version won't see it; use the agent version instead.

  2. Start a new script

    Go to script.google.com, click New project and name it Stock alert.

  3. Paste the script

    Replace everything in the editor with this. Put the product address and the words you found on the first two lines:

    const PAGE_URL = 'https://example.com/product';
    const LOOK_FOR = 'Add to cart'; // text that appears only when it's in stock
    
    function checkStock() {
      const html = UrlFetchApp.fetch(PAGE_URL, { muteHttpExceptions: true }).getContentText();
      const inStock = html.indexOf(LOOK_FOR) !== -1;
      const props = PropertiesService.getScriptProperties();
      const wasInStock = props.getProperty('inStock') === 'yes';
      if (inStock && !wasInStock) {
        MailApp.sendEmail(
          Session.getActiveUser().getEmail(),
          'Back in stock',
          'The page now says "' + LOOK_FOR + '":\n' + PAGE_URL,
        );
      }
      props.setProperty('inStock', inStock ? 'yes' : 'no');
    }
    
  4. Run it once and allow access

    Click Run and allow the script to fetch web pages and send email as you. If the item is already in stock you'll get an email right away, which proves it works.

  5. Check every hour

    Open Triggers (the clock icon), click Add trigger, choose checkStock, Time-driven, Hour timer, Every hour, and save. Delete the trigger once you've bought the thing.

Things that trip people up

  • Many shops build their pages with JavaScript, so the words you see aren't in the page source. Check the source first (step 1) or use the agent version.
  • Some shops block automated visits. If the script gets an error page, it can't watch that shop.
  • Pick words that only appear when the item is buyable. "In stock" can also appear in "Not in stock".