Skip to content

Can't get result from CallDevToolsProtocolMethodAsync #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ukandrewc opened this issue Jun 25, 2020 · 16 comments
Closed

Can't get result from CallDevToolsProtocolMethodAsync #304

ukandrewc opened this issue Jun 25, 2020 · 16 comments
Labels
feature request feature request

Comments

@ukandrewc
Copy link

ukandrewc commented Jun 25, 2020

Trying to call devtools protocol but not getting any results, I have Dev channel installed

Public Async Sub Test()
	Dim r = Await CoreWeb.CallDevToolsProtocolMethodAsync("DOM.getOuterHTML", "{}")
	Console.WriteLine(r)
End Sub

AB#27258673

@ukandrewc
Copy link
Author

Not the same for all calls, "Network.getCookies", does work.

@ukandrewc
Copy link
Author

It seems that ParametersAsJson may be the problem, I don't seem to be able to get a response when they are required.

This works:
CoreWeb.CallDevToolsProtocolMethodAsync("Network.getCookies", "{}")

Returns an empty array:
CoreWeb.CallDevToolsProtocolMethodAsync("Network.getCookies", "{""urls"":[""google.co.uk"",""www.google.com""]}")

@michael-russin
Copy link

For the cookies try adding the protocol. That works for me. For the DOM.getOuterHTML I haven't had any luck yet.

CoreWeb.CallDevToolsProtocolMethodAsync("Network.getCookies", "{""urls"":[""https://google.co.uk"",""https://www.google.com""]}")

@ukandrewc
Copy link
Author

@michael-russin Cheers, didn't think of that. I was going on .Net where only domain is required.

@ukandrewc
Copy link
Author

PS: I did try adding nodeId for getOuterHTML but nothing from that either.

@pagoe-msft
Copy link

@ukandrewc

Thanks for bringing this up - we have been investigating this and trying to determine if this is a bug on our side or a bug in CDP

@pagoe-msft
Copy link

@ukandrewc

This appears to be a bug on CDP side. I'll file a bug for them to look into and I've added a feature request on our end to provide better error messaging.

@ukandrewc
Copy link
Author

@pagoe-msft Great, thanks. While we're on better error messaging, is there any way to log executeScriptAsync errors in devtools?

@pagoe-msft
Copy link

@ukandrewc

We don't have support for that right now - but that's a really interesting feature request. Could you open a new issue for that, so we can track it separately in our backlog?

@pagoe-msft pagoe-msft added the feature request feature request label Jun 26, 2020
@ukandrewc
Copy link
Author

@pagoe-msft will do

@michael-russin
Copy link

You can get the getOuterHTML working by making 2 calls

// Get the document information
CoreWebView2.CallDevToolsProtocolMethodAsync("DOM.getDocument", "{}");

// parse the result JSON and read the nodeId

// get the outer html for the nodeId
CoreWebView2.CallDevToolsProtocolMethodAsync("DOM.getOuterHTML", "{\"nodeId\" : " +  nodeId + "}");

This will give the source you would see by doing an Inspect not what you would see with a View Source.

A basic sample can be found in the WebView2WindowsFormsBrowser project at https://github.com/michael-russin/WebView2Samples

@ukandrewc
Copy link
Author

ukandrewc commented Jun 28, 2020

@michael-russin Thanks, that is what I wanted to find out. Is it just document.documentElement.outerHTML.
At the moment, I'm making an XHR call to get the source, but was wondering if it is available locally.

@champnic
Copy link
Member

@ukandrewc Apparently even though the docs for getOuterHTML list all parameters as optional, at least one needs to be specified.

@ukandrewc
Copy link
Author

Great, thanks.

@WirelessMistress
Copy link

If you specify {"nodeId":1}
to the
DOM.getOuterHTML
command,
my impression is it gives you the entire HTML View Source Content

@WirelessMistress
Copy link

Sorry my bad
lemme correct my previous post

// Get the document information
var documentString = CoreWebView2.CallDevToolsProtocolMethodAsync("DOM.getDocument", @"{""depth"":-1,""pierce"":false}");

//var id = parse using a System.Text.RegularExpressions.Regex
// for @"(""backendNodeId"":)([0-9]+) on documentString

// get the outer html for the nodeId
CoreWebView2.CallDevToolsProtocolMethodAsync("DOM.getOuterHTML", "{"backendNodeId" : " + id + "}");

and you get all the view Source of the HTML document html-decoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

5 participants