Calling _event from Chrome Extension

2 posts, 0 answers
  1. Abdiasz
    Abdiasz avatar
    2 posts
    Member since:
    Mar 2015

    Posted 24 Mar 2015 Link to this post

    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.
  2. Abdiasz
    Abdiasz avatar
    2 posts
    Member since:
    Mar 2015

    Posted 25 Mar 2015 in reply to Abdiasz Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top