2

I am trying to get the file and line location of a function I saved in an object. If I am logging the object to the Chrome Dev Tools I see this:

enter image description here

Can I somehow from inside the code access [[FunctionLocation]]? Or is this something the Chrome Dev Tools add to the object? If so, is it possible to retrieve the function location when I am developing a Chrome Dev Tools extension or a Chrome extension?

2
  • 1
    This should better be able to help answer your question, but it appears to be no. Commented May 9, 2019 at 21:17
  • Looks like you asked a two part question and rather than start another thread the second part of your questions was not answered by the above link and is what I am curious about as well. 1. Can you access it in dev tools from the console? The link says no, mind you that was a couple years ago. 2. Are we able to access that from within an extension script? I have searched the APIs but cannot find it referenced and am developing an extension and I would like to find functions locations as part of the data points I am exposing. Commented Aug 7, 2019 at 13:11

1 Answer 1

2
  1. You still cannot access the internal properties through JavaScript.

  2. The information is exposed through the Chrome DevTools Protocol, as an InternalPropertyDescriptor. This is observable through for example Node.js:

    global.a = () => { /* test function */ };
    
    const s = new (require('inspector').Session)();
    s.connect();
    
    let objectId;
    s.post('Runtime.evaluate', { expression: 'a' }, (err, { result }) => {
      objectId = result.objectId;
    });
    s.post('Runtime.getProperties', { objectId }, (err, { internalProperties }) => {
      console.log(internalProperties);
    });
    

    yields

    [
      {
        name: '[[FunctionLocation]]',
        value: {
          type: 'object',
          subtype: 'internal#location',
          value: [Object],
          description: 'Object'
        }
      },
      {
        name: '[[Scopes]]',
        value: {
          type: 'object',
          subtype: 'internal#scopeList',
          className: 'Array',
          description: 'Scopes[2]',
          objectId: '{"injectedScriptId":1,"id":24}'
        }
      }
    ]
    

    with Node.js v12.3.1.

    Chrome extensions may interact with the Chrome DevTools protocol through chrome.debugger. I am not familiar with how DevTools extensions work, but you may find the Integrating with DevTools page to be insightful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.