Using browser automation in a Chrome extension without puppeteer-web

I’m trying to make a Chrome extension that can do some web scraping and browser automation. Here’s what I want to do:

  1. User puts in a URL
  2. They click a button
  3. The extension runs a script to scrape the page

Is this doable? I’ve looked into puppeteer, but it seems like puppeteer-web isn’t a thing anymore. Are there other ways to get this working?

I’m not sure if I need to use a different tool or if there’s a workaround for Chrome extensions. Any ideas on how to set this up? I’m pretty new to making extensions, so I’d appreciate any tips or suggestions.

Has anyone done something like this before? What did you use? Thanks for any help!

I’ve actually tackled a similar project recently, and I can share some insights. While puppeteer-web isn’t available, you can still achieve browser automation in a Chrome extension using the chrome.tabs API.

Here’s what worked for me:

First, make sure you have the necessary permissions in your manifest file, like ‘tabs’ and ‘activeTab’. Then, use chrome.tabs.executeScript to inject and run your scraping code on the target page.

For the scraping itself, I found using vanilla JavaScript with querySelector and querySelectorAll quite effective. You can extract the data you need and send it back to your extension using chrome.runtime.sendMessage.

One tip: Be mindful of rate limiting and respect website policies. I ran into issues with aggressive scraping, so implement delays between requests if needed.

It takes some trial and error, but it’s definitely doable. Good luck with your project!

I’ve implemented similar functionality in a Chrome extension before. While puppeteer-web isn’t an option, the chrome.tabs API provides powerful tools for this task. You’ll need to declare appropriate permissions in your manifest.json file, such as ‘tabs’ and ‘activeTab’.

For the actual scraping, I found that using vanilla JavaScript with DOM manipulation methods like querySelector and querySelectorAll works efficiently. You can inject your scraping script into the target page using chrome.tabs.executeScript.

One crucial aspect to consider is error handling. Make sure your script can gracefully handle cases where expected elements aren’t found on the page. Also, be mindful of performance - extensive DOM operations can slow down the page, so optimize your code where possible.

Remember to respect website terms of service and implement rate limiting if necessary to avoid potential IP bans.

hey alexj, i’ve done smth similar before. chrome.tabs API is ur friend here. u can use chrome.tabs.executeScript to run ur scraping code on the page. just remember to add the right permissions in ur manifest file. vanilla JS works great for scraping - querySelector and querySelectorAll are super helpful. good luck with ur project!