Coder Social home page Coder Social logo

perditionc / vbachromedevprotocol Goto Github PK

View Code? Open in Web Editor NEW
56.0 11.0 11.0 27.29 MB

VBA (Excel) based wrapper for Chrome Developer Protocol (CDP) - sorta a VBA version of Puppeteer/Selenium

Home Page: https://PerditionC.github.io/VBAChromeDevProtocol/

License: MIT License

VBA 99.36% FreeBasic 0.58% Visual Basic 6.0 0.05%
automate browser-automation chrome vba vba-macros

vbachromedevprotocol's Introduction

VBAChromeDevProtocol

VBA (Excel) based wrapper for Chrome Developer Protocol (CDP) - sorta a VBA version of Puppeteer/Selenium

Note: if you can use Puppeteer, Playright, Selenium, or some other tool - then use it! But if you can only use VBA, then this is meant to provide a means to automate Chrome or Edge based browsers. (Possibly Firefox via its limited CDP support, though currently untested/nonfunctional).

See https://chromedevtools.github.io/devtools-protocol/ for overview of Chrome Devloper Protocol

Initial work based on information and clsEdge from https://www.codeproject.com/Tips/5307593/Automate-Chrome-Edge-using-VBA

Primarily connects directly to browser using Chrome/Edge's ability to use the CDP via pipes when started, however, now also has basic support for connecting to browser through standard websocket interface so can reuse already open browser if started with CDP port 9222 listening.

Currently primarily tested with and assumes working with Edge; however will detect and support spawning Chrome and possibly FireFox (Chrome should work at least in websocket mode, Firefox is untested)

TODO

  • improve/add usage documentation
  • generator needs some more work (still has some class names too long/clash, still has some clashes with reserved words, incorrectly assumes class for unspecified object)

Note

when downloading the source files from git, be sure to convert to DOS/Windows CRLF style endings for the text files or Office may import as wrong module type (regular modules instead of class modules) - to be updated to ensure git always does this

Usage

see Example.xlsm - documentation to be added

Special thanks / uses source based on

Testing and enhancements by Jason Pullen and Kenneth J. Davis

vbachromedevprotocol's People

Contributors

moaoci avatar perditionc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vbachromedevprotocol's Issues

Error handling of disconnected browser

The error ( halt to the STOP instruction ) occurs when the browser is manually disconnected while the user macros are running. Might also happen if www site returns a time out.

Mine occurs in AutomateBrowser.querySelectorAll, (other functions might be also be affected.)

ErrHandler:
Debug.Print "AutomateBrowser.querySelectorAll - " & Err.description
Stop
Resume
End Function

The RESUME after the STOP will rapidly bring back to the STOP and on and on.

The documentation says «' Note: resulting Dictionary will be empty (0 items) if an error or no matching elements found»

Changing RESUME to RESUME NEXT seems to work, returning 0 items as stated.

After returning 0 items, is there a way to verify if browser is unavailable or if querySelectorAll simply did not find anything ? If so, the STOP could also be removed.

I am not at ease with the whole AutomateBrowser module. Other ErrHandler: simply stop before end function, no resume. Can someone verify ?

Enhance browser selection and enable additional inlineCommands

To better control which browser to launch (without changing LaunchBrowser default logic).

Add two parameters
additionalInlineCommands
killWithoutAsking

Allow these parameters and whichBrowser to follow thru the whole sequence AutomateBrowser.Launch, clsCDP.Launch and Browsers.LaunchBrowser

Create functions to choose browserType outside of LaunchBrowser preset order
getFirstAvailableBrowser (browser1, browser2, browser3) that will get the first non running installed browser
getFirstInstalledBrowser (browser1,browser2,browser3)

Add noBrowser to browserType enumeration

Show / document examples in examples.xlam

Firefox

Test Firefox and fix & document any features that don't work

Class modules incorrectly importing as Modules due to line ending issue

I tried importing all the files to my Microsoft Outlook project, but all the class modules got imported as regular modules.

I am using the following environment:

  • Microsoft Outlook: Version 2108 (Build 14326.20852), Microsoft 365
  • Microsoft Visual Basic for Applications 7.1: Version 1119
  • Windows 10: Version 20H2 (OS Build 19042.1586)

Currently, I am inserting new Class modules and copy-and-pasting the contents. But there are a lot of files 😭

Any help would be appreciated.

'hInPipe = hStdOutRd' throws error 458 (!)

I'm trying this library for the first time after an old failed try and I now can't even get the simple cdp.launch "https://www.google.com/" (in test1a) to work:
the instruction hInPipe = hStdOutRd of Functions.SpawnProcess throws error
458 -"Variable uses an Automation type not supported in Visual Basic"

An F8 on that instruction goes directly to the clsCDP.launch line Debug.Print "cldCDP.launch() - Error: " & Err.description that prints this:
"cldCDP.launch() - Error: Variable uses an Automation type not supported in Visual Basic"

hInPipe is a Variant/LongLong (value=0)
hStdOutRd is a LongLong (value=5536^)

I don't even know how it's possible for VBA to fail on such a plain simple value assignation.

Code generator

Improve / rewrite CDP code generation. Some commands are not supported due to too long class names and some not supported as not properly mapping CDP type to valid VBA type.

Browser paths

Browser paths need to be queried for instead of using hard coded paths. Different installs may and do use different paths.

Can't make it work. cldCDP.launch() - Error.

Haven't been able to make any of the examples of Examples.xlsm work.

Using Windows 10 and 64-bit Excel.

Any of them finish with this immediate window message:


Failed to write CDP message!
{"method":"Target.setDiscoverTargets","params":{"discover":true}, "id":2}

cldCDP.launch() - Error: Error defined by application or object

When all browsers are closed, nothing happens (only the mentioned immediate window message).
When only Chrome or only Edge is running, no other browser starts and only the mentioned immediate window message appears.
When Chrome and Edge are running, FireFox starts and finally the mentioned immediate window message appears.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.