apache / cordova-plugin-inappbrowser

Apache Cordova InAppBrowser Plugin
https://cordova.apache.org/
Apache License 2.0
1.12k stars 2.15k forks source link

Can't Retrieve HTMLCollection Object #1058

Open Vladeouz opened 5 months ago

Vladeouz commented 5 months ago

Bug Report

Im trying to accessing the data inside of HTMLCollection.

Problem

I cant accessing it, and retrieve the data.

What is expected to happen?

it should return the data inside the HTMLCollection

What does actually happen?

It always gives null.

Information

this is the result of the print image

Command or Code

InAppBrowserRef.executeScript({ code: console.log('masuk di script'); window.addEventListener('DOMContentLoaded', function () { console.log('Im here 1'); }); document.addEventListener('DOMContentLoaded', function () { console.log('Im here 2'); }); window.addEventListener('load', function () { console.log('Im here 3'); }); document.addEventListener('load', function () { console.log('Im here 4'); }); const elements = document.querySelectorAll(".text-grey"); console.log('this is elements', elements); console.log('this is the lengthnya', elements.length); console.log('trying to open the 0 index', elements.item(0)); const newArray = Array.from(elements); console.log('this is the new Array', newArray); newArray.forEach(function (element) { console.log('result of forEach', element); }); Array.from(elements).forEach((element) => { console.log(element.innerText) }); }, function (result) { console.log('Script Executed:', result) }) }

Environment, Platform, Device

Samsung A50s Android 11

Version information

Operating System - Windows_NT(10.0.22631) - win32/x64 NodeJs - 16.20.1

Global packages NPM - 8.19.4 yarn - 1.22.19 @quasar/cli - 1.3.2 cordova - 12.0.0 (cordova-lib@12.0.1)

Checklist

breautek commented 5 months ago

I do not believe that this is an issue with the in-app-browser.

Cordova doesn't implement browser features, and HTMLCollection / document.querySelectorAll is a browser feature implemented by the webview.

HTMLCollection is a "live" object which means it can change, it's reflective of the DOM state, so if the DOM state changes, so will the HTMLCollection object. It is weird that it appears to change within script execution though. By the time it reaches console.log('this is the lengthnya', elements.length);, it shows that the collection is empty, so naturally elements.item(0) would return null.

Are you sure that the DOM nodes isn't being manipulated and your .text-area nodes aren't being removed from the DOM?