0

I am injecting a Javascript-File via a Chrome-Extension on a webpage that uses SAPUI5. I want to get the model in the binding context of some UI5-Input elements and in order to do so, I need to get to the inputs via document.getElementsByTagName. (or is there another way?)

This only works if they are already rendered. Unfortunately the ready or load events fire too early, when not everything is rendered yet.

Is there a way for me to know when the inputs have rendered?

Edit: I do not have access to the source code of the page, everything I do has to be in the injected script.

  • Is this a UI5 element? You haven't provided any code. if an `id` is set, you can get the binding context using `byId()` function. – O.O Jan 26 '19 at 17:11
  • It is a UI5-Element. I don't know the IDs of the inputs, I just know their type. But even if I did, byId() wouldn't work here, if the element is not yet rendered in the DOM-Tree or UI5-Tree, correct? – Konstantin Dobler Jan 27 '19 at 15:15
  • Another approach: 1. Wait for model binding to complete. Check here.https://stackoverflow.com/questions/29770332/perform-action-after-the-binding-is-complete 2. Is there a way for you to attach a custom class to UI5 input elements created ? If so, then use, `$(.customClass)[0].control()`. This is return a UI5 element. From there you can fetch its binding Context. The problem is very interesting. Wish there was more you could share with us. May be a dummy code online for us to play with ? – Rahul Bhardwaj Jan 27 '19 at 17:21
  • My problem is I don't have the model stored somewhere in a variable, I have to somehow get it from the page. What I described in my question is an idea on how get to the point where I have the model stored in a variable in my script. – Konstantin Dobler Jan 30 '19 at 22:02
  • Do you have access to the global `sap` object from the target page? E.g. can you perform `sap.ui.getCore()`? – Boghyon Hoffmann Feb 10 '19 at 20:21
  • Yes, I can do that. – Konstantin Dobler Feb 11 '19 at 14:36

2 Answers2

0

To make sure everything is renedered before firing your events, sapui5 has the function onAfterRendering.

All logic written in that function will only be executed after the control is rendered.

When a rerender of the control is rendered, the onAfterRendering is triggered again.

KristoffDT
  • 471
  • 3
  • 14
  • Unfortunately I dont have access to the source code of the page, everything I do has to be inside the injected script. This function needs to be called on a control right? My problem is that I can't get the control as an object until it is rendered and I can get it via byId(). Is there any way I could get to the control before it is rendered? – Konstantin Dobler Jan 27 '19 at 15:19
0

In the end I did it like this:

I already had event listeners attached to click and key events. Every time the handler is called, I check if document.getElementsByTagName('input') returns the inputs I need.

If yes e. g. the rendering of the inputs is complete, I set a boolean that the page is loaded completely and execute my code.