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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

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

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

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

This Is How To Get A Substring of a Wide String in C++

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