Skip to content

[Q/A] How to access __reactInternalInstance, __reactEventHandlers? #174

Answered by hijiangtao
aaamoon asked this question in Q&A
Discussion options

You must be logged in to vote

@aaamoon As far as I know, we can achieve this goal with three parts:

  1. Send messages from content script (content UI script)
  2. Get the logic code that you want to deal with DOM packed and inject it into MAIN
  3. Get messages from MAIN and deal with DOM, and then return the results

For content script:

// - postMessage to MAIN
window.postMessage(...)

// - get message from MAIN
window.addEventListener("message", ...)

For background script:

const injectScript = () => {
  console.log(document.querySelector('#root').__reactInternalInstance$)

   window.postMessage(...)
}

chrome.scripting.executeScript(
    {
      target: {
        tabId
      },
      world: "MAIN", 
      func: injectScript
   …

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by louisgv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed question Further information is requested need test The issue require further testing, it might have been fixed
3 participants
Converted from issue

This discussion was converted from issue #164 on September 03, 2022 18:37.