C++Language FeatureLearn C++

Learn To Use Script Injection Method In Modern C++ On Windows With EdgeBrowser

teal white and pink paint

If you want to analyze browsed web pages, first you need a web browser component. We can use Script Injection methods to get more details about the HTML or XML documents, for example to get Title of that webpage, or full Body of that page, or value of an element. This is very useful for data mining or for analyzing web pages, this can be applied with time intervals for refreshing web pages, like pages about weathers, news etc.

Document Object Model (DOM)

The Document Object Model (DOM) represents an HTML or XML document in memory and it is the data representation of the objects that comprise the structure and content of a document on the web. So you can use APIs to edit or create web content and applications. DOM is described well on mozilla.org here.

For example for HTML and XML documents;
DOM Object Document properties can be found here https://developer.mozilla.org/en-US/docs/Web/API/Document
DOM Object Body properties can be found here https://developer.mozilla.org/en-US/docs/Web/API/Document/body

How HTML XML Injection is Performed

DOM document has properties and iinnerHTML is the property of DOM document and with innerHTML, we can write dynamic HTML code. It is used mostly for data input fields like comment fields, questionnaire forms, registration forms, etc.

Script Injection Method in Modern C++

In RAD Studio, C++ Builder 10.4 and above there is a EdgeBrowser (TEdgeBrowser) component to navigate on web pages and it wraps the latest Microsoft WebView2 component. The EdgeBrowser component is easy to use to navigate on web pages than the previously WebBrowser which has some incompatibilities on pages. This new web browser supports fully WebView dynamic library of Canary version. If you are new to EdgeBrowser please read this and Learn To Develop Your Web Browser App in C++ Builder on Windows (EdgeBrowser).

With these information above, if you are able to successfully run EdgeBrowser as in examples; now we can easily add Script Injection method to retrieve the full text of document. This method fully gets all document data as in UnicodeString which means it can be used to analyze web pages in any language.

In C++ Builder, EdgeBrowser has Script Injection method. To apply this we should use this line as below;

or you can directly navigate from Text of your Edit as here;

For example you can obtain full body of document with this Script execution;

Here we are injecting to ask this.document property and DOM object will return this request. To obtain this request, go to properties of EdgeBrowser, double click to ExecuteScript event and add this code to copy content of the results from web page to Memo

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?

Worth reading...
Introduction To C++ Windows Development With C++Builder