[a-134] Error 0x80020101 on ComObject - [Item vs Property access] Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

[a-134] Error 0x80020101 on ComObject - [Item vs Property access]

13 May 2021, 16:43

Hi guys!

I have been playing a bit with v2 and found myself hitting Error Error 0x80020101 when accessing the DOM while using an InternetExplorer.application object for testing.

This code here is the v1 code I was testing:

Code: Select all

IAutomation := ComObjCreate("InternetExplorer.Application")

IAutomation.Visible := true
IAutomation.Navigate("https://www.autohotkey.com")
document := IAutomation.document

while (IAutomation.busy || IAutomation.readyState != 4) 
	sleep 50

while (!document.querySelectorAll("div.mbr-article a"))
	sleep 50

if (document.querySelectorAll("div.mbr-article a"))
{
	document.querySelectorAll("div.mbr-article a")[1].scrollIntoView(true)
	document.querySelectorAll("div.mbr-article a")[1].click()
}
When trying this code on v2 I get the error mentioned above:

Code: Select all

IAutomation := ComObject("InternetExplorer.Application")

IAutomation.Visible := true
IAutomation.Navigate("https://www.autohotkey.com")
document := IAutomation.document

while (IAutomation.busy || IAutomation.readyState != 4) 
	sleep 50

while (!document.querySelectorAll("div.mbr-article a"))
	sleep 50

if (document.querySelectorAll("div.mbr-article a"))
{
	document.querySelectorAll("div.mbr-article a")[1].scrollIntoView(true)
	document.querySelectorAll("div.mbr-article a")[1].click()
}

While testing I noticed that this is the offending part: document.querySelectorAll("div.mbr-article a")[1], and I assume it has to do with the new difference in accesting items and properties in v2... It starts working perfectly fine as soon as I change the code to:

Code: Select all

if (document.querySelectorAll("div.mbr-article a"))
{
	document.querySelectorAll("div.mbr-article a").1.scrollIntoView(true)
	document.querySelectorAll("div.mbr-article a").1.click()
}
my question is:
Is this behavior correct? I would assume it is not, since that syntax implies that .1 is a property and not an array item as it actually is.
Is there any workaround to not use that syntax atm?

Thanks for the help!
Projects:
AHK-ToolKit
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]  Topic is solved

14 May 2021, 06:15

Array elements are properties in JavaScript, and [] there is used to access properties, not specifically array elements. I suppose that any object model intended primarily for JavaScript would also expose array elements as individual properties. The only alternative would be to use an accessor method like item() or set().

I think [] in v2 invokes DISPID_VALUE, which I guess doesn't work with objects intended for JavaScript. I'm not really sure what objects that works with (for get/set). It could probably fall back to invoking a property by name if DISPID_VALUE doesn't work.
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

14 May 2021, 07:21

lexikos wrote:
14 May 2021, 06:15
Array elements are properties in JavaScript, and [] there is used to access properties, not specifically array elements.
I was not aware of that.
lexikos wrote:
14 May 2021, 06:15
I think [] in v2 invokes DISPID_VALUE, which I guess doesn't work with objects intended for JavaScript. I'm not really sure what objects that works with (for get/set). It could probably fall back to invoking a property by name if DISPID_VALUE doesn't work.
That sounds good! It would make writing DOM automation scripts a bit easier since we would just write the code as we are used to.
Projects:
AHK-ToolKit
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

14 May 2021, 23:12

Actually, the documentation for querySelectorAll (and type information for coclass HTMLDocument) indicates it should return an IHTMLDOMChildrenCollection. ComObjType shows that it returns a StaticNodeList, whose default interface is DispStaticNodeList. Sure enough, mshtml.tlb confirms StaticNodeList implements these interfaces. Both interfaces have a member named "item" which has id 0, according to mshtml.tlb. However, the object responds to id 0 by returning 0x80020101, and passing "item" to IDispatch::GetIDsOfNames returns a non-zero id.

(The only difference between x[1] and x.item[1] is that the latter uses GetIDsOfNames to get the ID of "item" before calling IDispatch::Invoke, while the former uses DISPID_VALUE, i.e. 0.)

In other words, the type information in mshtml.tlb says it should work, but it doesn't.

Outside of mshtml, I found several objects that had a member with id 0 and tested a few with []; those worked.

Even in mshtml, there are other cases with member id 0 that work, such as document.all[1]. Actually, document.all(1) (note the parentheses) works in the developer console in IE, whereas document.querySelectorAll("div.mbr-article a")(1) gives a "Function expected" error. It does the same if the expression preceding (1) is first assigned to a variable.

I don't think it's appropriate to invoke the object a second time after receiving 0x80020101. Maybe for a result like DISP_E_MEMBERNOTFOUND, but that won't help this case.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

15 May 2021, 05:22

lexikos wrote:
14 May 2021, 23:12
In other words, the type information in mshtml.tlb says it should work, but it doesn't.
yeah i find this very weird. why doesnt it? is this a microsoft bug? or perhaps its defined elsewhere diffrently(where the mapping is different or perhaps even nonexistent at all)?
image.png
image.png (149.65 KiB) Viewed 2028 times

also https://www.autohotkey.com/v2/v2-changes.htm#com-objects-comobject should probably mention that [Params*] exclusively invokes with DISPID_VALUE, whereas in v1:
Changed objects to support x[,y], x.y[,z] and x[](y).

User-defined objects can utilize this by specifying default values for parameters of properties and meta-functions. For __Call, the first parameter is omitted, as in x.__Call(,y).
COM objects invoke DISPID_VALUE if the member name is omitted. For example, x[] retrieves x's default property and fn[]() can be used to call JScript functions.
only x[], x[, y] and other similar omitted first param likes ever do
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

11 May 2022, 09:47

Related to this issue, how can I enumerate a NodeList?

I am trying to do this:

Code: Select all

for item in document.querySelectorAll('li.nav-item>a')
but obviously, that wouldnt work given the discussion above.

I think I can do a loop with the length like so:

Code: Select all

days := document.querySelectorAll('li.nav-item>a')
loop days.Length
{
	day := days.item(A_Index-1)
	OutputDebug day.href
}
But is there any way I could use the for loop with these types of objects?
Projects:
AHK-ToolKit
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

12 May 2022, 13:51

Don’t think so with IE unless you use a helper to put the entries into an array.
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

13 May 2022, 09:10

kczx3 wrote:
12 May 2022, 13:51
Don’t think so with IE unless you use a helper to put the entries into an array.
I would assume that ComObject("HTMLfile") is also based on the IE engine, right?
Projects:
AHK-ToolKit
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

10 Sep 2022, 15:22

Hello guys,

This bug is still prsent in beta.8 but I found something hopefully interesting:

Code: Select all

td := Rows[a_Index-1].getElementsByTagName("TD")

OutputDebug td[1].getElementsByTagName("A")[0].getAttribute("title") " - " ;<-- using array accessor
		  . td.item[1].getElementsByTagName("A").item[0].getAttribute("title")
When trying this code both items get resolved correctly.
if I change it to querySelectorAll I get the result described in the topic.

Interestingly enough both getElementsByTagName and querySelectorAll return an object
with the same id {C59C6B12-F6C1-11CF-8835-00A0C911E8B2}.

I hope this could be resolved at some point because I think we are more used to using querySelectors instead of getElementsBy...
Projects:
AHK-ToolKit
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

10 Sep 2022, 18:24

@RaptorX
As discussed and illustrated above, we already determined the original issue was due to a bug in the MSHTML implementation. It is not in beta.8.

It looks like I didn't point out the obvious solution, that if array elements are properties, to access them you should use property syntax. That would be arr.1 or arr.%index%.
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

10 Sep 2022, 22:05

lexikos wrote:
10 Sep 2022, 18:24
@RaptorX
As discussed and illustrated above, we already determined the original issue was due to a bug in the MSHTML implementation. It is not in beta.8.

It looks like I didn't point out the obvious solution, that if array elements are properties, to access them you should use property syntax. That would be arr.1 or arr.%index%.
Alright, i just use the .item[•] notation as it is clearer.
I just had hope that at some point a workaround could be implemented because even if it's not an ahk bug it makes ahk behave inconsistently (.getElementsByTagName CAN be accessed td[1] but .querySelector cant).
Projects:
AHK-ToolKit
flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

Re: [a-134] Error 0x80020101 on ComObject - [Item vs Property access]

01 Nov 2022, 08:39

I have a script that has been running for several years. I've just started getting this error. The part of the script in error is based is taken from a snippet I found on these forums, viewtopic.php?p=372304&sid=acf0d2f1412d219ec16de7c4c69efd2c#p372304.

I can open a new thread if necessary. I posted in this one because the error looks similar.
image.png
image.png (19.38 KiB) Viewed 856 times

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: lexikos, songdg and 28 guests