growthbook / devtools

GrowthBook DevTools extension for Chrome
MIT License
5 stars 5 forks source link

Changing feature values doesn't work when using Chrome devtools in a separate window #39

Closed CameronDowner closed 11 months ago

CameronDowner commented 1 year ago

Hi,

I'm using the devtools while using Chrome DevTools in a separate window pop out but the feature flag values aren't updating.

I think this is caused by the function sendMessage in controller.ts not being able to find the correct tab, as it's no longer the currentWindow - the DevTools window is.

I've cloned and tested the following solution, and I believe it works as expected. Let me know if you'd prefer me to open a pull request.

Current

function sendMessage(msg: Message) {
  chrome.tabs &&
    chrome.tabs.query(
      {
        active: true,
        currentWindow: true,
      },
      (tabs) => {
        chrome.tabs.sendMessage(tabs[0].id || 0, msg);
      }
    );
}

Suggestion

function sendMessage(msg: Message) {
    if (chrome.tabs && chrome.devtools?.inspectedWindow) {
        const  { tabId } = chrome.devtools.inspectedWindow;
        chrome.tabs.sendMessage(tabId || 0, msg);
    }
}
bttf commented 12 months ago

@CameronDowner Thank you for the detailed report. Your fix makes sense! This is related to another bug we've noticed which I'm writing an issue for now. If you'd like to submit a PR we certainly encourage it. Thanks!

CameronDowner commented 12 months ago

@bttf I've open PR #44 that should fix this issue