"Force element state" (pseudo-class)

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

"Force element state" (pseudo-class)

Postby wizofaus » Tue Sep 08, 2015 7:02 pm

Hi,
I'm trying to work out how to programmatically force an element state to e.g., hover, active etc. as per the Inspector/dev-tools "force element state" command, so I can query the computed style on an element when it's in a particular state.
I'm having trouble seeing how to do this if there's no InspectorBackend available. I'm actually using CefGlue but I accept it might not have the capacity to do this, I'm prepared to extend it to do so if needed.
I was hoping there might be a way via JavaScript but haven't had any luck there. Even simulating a mousemove to generate the hover state might work though it will be problematic for over pseudoclass states.
Thanks for any advice
Dylan


P.S. I've tried the remote debugging port, with some limited success - I can find the node and send CSS.forcePseudoState to set the 'hover' state, then call CSS.getMatchedStylesForNode to determine that a particular style is applying, but for some reason it's not affecting the outcome of CSS.getComputedStyleForNode (and certainly not of the regular window.getComputedStyle).
wizofaus
Newbie
 
Posts: 8
Joined: Sun Aug 02, 2015 11:47 pm

Re: "Force element state" (pseudo-class)

Postby wizofaus » Tue Sep 08, 2015 10:07 pm

Hah, turns out the debugger API works just fine, as long as you do:

send { id: 1, method: "Inspector.enable" }
send { id: 2, method: "DOM.enable" }
send { id: 3, method: "CSS.enable" }
send { id: 4, method: "DOM.getDocument" }
send { id: 5, method: "DOM.querySelector", params: { nodeId: 1, selector: "a" } }
nodeId = response.result.nodeId;
send { id: 6, method: "CSS.forcePseudoState", params: { nodeId:, forcedPseudoClasses: [ "hover" ] } }

Then you can use the regular getComputedStyle, or the CSS.getComputedStyleForNode.
The trick seemed to be in the manner you call the "enable" functions first.
wizofaus
Newbie
 
Posts: 8
Joined: Sun Aug 02, 2015 11:47 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 31 guests