This is a migrated thread and some comments may be shown as answers.

Calling _event from Chrome Extension

1 Answer 59 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Abdiasz
Top achievements
Rank 1
Abdiasz asked on 24 Mar 2015, 04:17 PM
Hello,

I'm new to this forum, spending my last few hours searching for information/help, but with no results I decided to join and ask. Hope it's correct place, if not then please move it to more appropriate section.

I have moderate knowledge of C# and Java but was tasked with creating simple(at first glance) Chrome Extension. I wasn't familiar at all with all of quirks and small things that JS comes with, but was doing ok until I got to a point, where I have no idea what to do.

I'm using latest Chrome(41.0.2272.89.m as I'm writing this), with Windows 7 Enterprise.

The problem is that when user fills out one NumericBox and leaves focus(with TAB or clicking something else) onblur() is invoked and some other fields are updated with entered data. But I need to fill these boxes with extension that parses user provided string. And here is root of my problem.

In Chrome developer console, elements pane, when I locate element in question and look at event listeners I can see handler at blur event. Same goes for console:
var element=InputFormOnPageSampleNameForExamplePurposesOnly
element._events.blur[0].handler()  //<-this actually executes and updates what I need!

But, when I look at:
element.blur
//returns
function blur() { [native code] }
 
element.blur()
//returns
undefined

In my extension, to update them all I put element IDs in an array, then foreach it with function that I would like to call blur() handler on each of these elements, but I can't manage to do this and after around 4 hours of research I'm feeling stuck.When debugging with breakpoint inside loop I can see that current processed element has all regular properties except these written in ALL_CAPS and _events 
Is it even possible to fire this event from Chrome extension? Everything else so far works ok, but without this continuing this extension will be pointless as user will need to click each field at least once in order to update it.

And I have tried also trying to get those field select()-ed or click()-ed and even simulate keypresses, but nothing helped.

1 Answer, 1 is accepted

Sort by
0
Abdiasz
Top achievements
Rank 1
answered on 25 Mar 2015, 10:40 AM
Ok, good night sleep yields best results.

I know it's probably easy and simple for most of you, but just in case someone is looking through google with similar question:

It's possible to do with Chrome extension, "just"
1. Inject content script, which will define method calling required event(in my example getting it by id and then just executing proper handler).
2. Next, add custom event handler in injected script to receive data from extension, attach it to document
3. In extension, when you need to do execute handler on given element, just dispatch your custom event with data like element id.
4. Yay, it's working.

Ok, that's it. This particular problem - solved.
Tags
Ajax
Asked by
Abdiasz
Top achievements
Rank 1
Answers by
Abdiasz
Top achievements
Rank 1
Share this question
or