3

I wrote a chrome extension to add some functionalities to a third-party website written in Angular. In order to read values (e.g. from textboxes), my javascript code would select the DOM item and read the ngContext property to extract the values:

function getSubmissionDataFromMemory() {
    var submission = undefined;
    document.querySelector("app-submission").__ngContext__.forEach(function(contextItem) {
        if (contextItem != undefined && contextItem[0]) {
            if (contextItem[0].nodeName == "APP-SUBMISSION") {
                return contextItem.forEach(function(nodeCtxItem) {
                    if (nodeCtxItem && nodeCtxItem.code != undefined) {
                        submission = nodeCtxItem;
                    }
                });
            }
        }
    });
    return submission;
}

With the migration to Angular 15, this code is no longer working as Angular is now only returning the ID of the LView in the ngContext property.

My question is: now that ngContext only returns the ID of the LView item, how and where can I access these LViews from my browser console?

  • I tried looking into other window objects but could not immediately find where these would be stored
thezucc
  • 111
  • 1
  • 2
  • 3

1 Answers1

0

Did you try ng.getInjector(ng.getComponent(####) (where #### is the element corresponding to your component) ?

The injector contains the lView and the tNode.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • 2
    Unfortunately this feature is not present in production mode, only in dev environments. I need this for a Chrome extension so I cannot enable dev mode on the developers' behalf – thezucc Feb 24 '23 at 13:20