Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access items inside Webpack bundle in browser console

I am using Typescript with Webpack (debug build using source maps). I can access Static class files in the sources tab normally. However, the class name itself is undefined at the global scope.

class SomeStaticClass {
  public static doSomething() {
     console.log("I just did something!");
  }
}

I would like to access / call

SomeStaticClass.doSomething() 

from console in the browser (say Google Chrome Inspector Tools). How can I achieve this?

like image 396
workwise Avatar asked Aug 17 '26 18:08

workwise


1 Answers

I managed a workaround like the following. In the main exports.tsx (assuming this is the top level export):

import { StaticClassToBeExposed } from '...SomeFile';

if(type of window !== undefined) {
   window.StaticClassToBeExposed = StaticClassToBeExposed;
}
like image 171
workwise Avatar answered Aug 20 '26 08:08

workwise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!