Executing Javascript code based on data found within an HTML document

I am currently working on a C-based application that accesses web pages to retrieve HTML data, including JavaScript code. In order to execute the JavaScript code, I have integrated V8 (the JavaScript engine used in Chrome) into my C code.

I am seeking advice on the best approach to follow for executing JavaScript code within the HTML data. One possible logic is:

  1. Load and execute all downloaded JavaScript files using V8. This will load the JavaScript into memory, but may not provide any useful output.

  2. When encountering HTML data with a script tag containing JavaScript code, execute the JavaScript within the script tag.

Is this approach correct, or am I missing something? If you have a better suggestion, please share your insights.

EDIT1
My main question revolves around determining the most effective logic when parsing through HTML data and executing JavaScript contained within it.

EDIT2
For example, tools like JMeter are able to receive HTML and JavaScript data and execute the JavaScript code, typically done in Java. However, I need to achieve the same functionality in C by leveraging V8 integration. What I am trying to figure out now is the optimal method for scanning HTML data and executing JavaScript code within it.

Answer №1

Attempting to accomplish this task in such a manner is not feasible. V8 serves as solely the JavaScript interpreter/VM, lacking many necessary APIs found within browsers like DOM, time, networking, and more. Attempting to utilize web pages that rely on these APIs will inevitably lead to failure.

The most appropriate solution involves integrating a complete chromium or similar browser backend into your application.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigate to another HTML division using data-toggle

I have 2 HTML documents index.html and services.html In services.html, I have the following code: <a class="nav-link" data-bs-toggle="tab" href="#ds-tab">Data Science</a> <a class="nav-link" data-bs- ...

Express.js Res redirection problem occurring with Backbone.js due to failure in redirecting hashtag URLs

Issue Summary: Having trouble with Express.js redirect functionality. The problem occurs when trying to redirect after entering /#impulse, but works fine with /impulse/. Server processes the request for /#impulse before applying redirect checks, which re ...

The size of the Webpack bundle grows with each subsequent build

For my project, I am utilizing webpack to package it as a library. The project consists of a components library, and for each component residing in its own directory under src/ui, I am creating small bundles. Here is an example component structure: src/ ...

After using driver.execute_script, the variable results in nil

Attempting to retrieve a lengthy string of URLs separated by commas is proving challenging. The code functions correctly in the console, but when running the script, the ruby variable urls_list remains nil. require 'rubygems' require 'selen ...

Using doxygen to preprocess a C file

Looking at my C code, I am interested in preprocessing it with doxygen in order to generate a call graph. I have set ENABLE_PREPROCESSING = TRUE. Here is the code snippet: #define CALL_ENABLE 1 #define REPORT_ERROR_TEST 0 #if (CALL_ENABLE == 1) void Func ...

Utilizing AngularJS to invoke REST API calls within a for loop and efficiently manage priority for the visible content area

Currently, I am dealing with an array containing over 400 data IDs related to different fruits. My goal is to make API calls in a for loop to retrieve relevant information about each fruit. While this works fine for smaller lists, it fails when dealing wit ...

How can I show the total sum of input values in a React.js input box?

Is there a way to dynamically display the sum of values entered in front of my label that updates automatically? For example, you can refer to the image linked below for the desired output Output Image I have initialized the state but I'm struggling ...

Explaining the process of supplying an event to the setState function

I'm struggling with the following code snippet: h(e) { console.log(e.target.value); this.setState(state => { return {editData: e.target.value}; }); } Unfortunately, it seems like it's not working as e ...

Firebase will automatically log users out after one hour of inactivity

After conducting thorough research, I have learned that Firebase updates a refresh token every hour because Firebase ID tokens expire after one hour. It is mentioned that the automatic refreshing of tokens by Firebase occurs without any action required fro ...

Creating an If statement tailored for a particular image source: a step-by-step guide

In the program I am running in Dreamweaver, there is a specific line of code that looks like this: function go() { if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) ...... ...... ..... ...

Expand the scope of the javascript in your web application to cater

I am in the process of creating a web application that utilizes its own API to display content, and it is done through JavaScript using AJAX. In the past, when working with server-side processing (PHP), I used gettext for translation. However, I am now ...

Using xsl:attribute with conditional statements and handlebars for dynamic content

I attempted to use handlebars to set xsl:attribute. Here is the code snippet: <input type="text"> {{#if_eq line_type 0}} <xsl:attribute name="disabled">true</xsl:attribute> {{/if_eq}} </input> Unfortunately, this approach ...

Can someone explain the significance of (char*)1 in programming?

Can someone explain the significance of this code snippet? ptr=(char *)1; I've tried searching for an answer, but I'm still unsure about what it means. I understand the concept of pointers, so no need to elaborate on that. ...

Concealing a label for a certain range of values

Does anyone have a clever solution for dynamically hiding a label associated with an input range element when the value is below a certain threshold? And then reappearing it once the value surpasses a specific minimum? Any thoughts on this matter? Thank ...

A step-by-step guide on smoothly transitioning between elements using Vue-Carousel on a click event

Today marks my first question here and I'm excited! Can anyone guide me on how to implement sliding on click element with Vue-Carousel? I want to slide to the right with just a single click on my input button. Here's the code snippet I have base ...

Utilizing Ajax to Invoke Wordpress Functions from a Client's Browser

Currently working on setting up a WordPress website integrated with WooCommerce, while also developing an HTML5 app for my small online store. I am looking to utilize Ajax to call WordPress functions like search directly from my HTML5 app and receive the r ...

Incorporate JavaScript .js file into the webpage asynchronously to invoke a web service

JavaScript File: JScript.js function Helloworld() { $(document).ready(function () { $.ajax ({ type: "POST", url: "Default.aspx/Helloworld", contentType: "application/json; charset=utf-8", dataType: "json", a ...

Uploading files asynchronously in Internet Explorer 8

Currently, I am on the lookout for sample code that allows asynchronous file uploads in IE8 using Ajax. While having upload progress would be a bonus, it is not essential. Moreover, I specifically need PHP code to handle the uploaded files on the server ...

What determines the priority of execution in the execution context stack?

Check out this insightful tutorial on execution context in JavaScript here. It's interesting how the order of invoking functionA() and console.log("GlobalContext") differs in terms of writing code versus the execution context stack. I'm curious, ...

The issue arises with AJAX functionality not functioning properly when the checkbox is left unchecked

I want to update the flag value in my database every time I check or uncheck a checkbox. However, for some reason, the AJAX call only triggers when changing the checkbox from checked to unchecked. HTML <table id="example" class="display" cellspacing= ...