jomarko commented on issue #151: URL: https://github.com/apache/incubator-kie-issues/issues/151#issuecomment-1887098957
@tiagobento @thiagoelg thank you both for links, they helped me in browsing more information about possible solution. ### Good news I was able to achieve 'Open in KIE Sandbox' botton on different github instances, yay! ### Bad news It has limitations described below #### Github instance version Each deployed github instance may be different in version, so it means also the locators of our chrome extension for displaying buttons needs to be different. I was able to find a locator for a github repository home screen, that was same for two different github instances, however I was not able to find such a locator for a github asset screen. We should probably add some description into our chrome extension, what github instance versions are supported. Or limit the scope of our chrome-extension only for github repository home screen that is maybe the most stable part of the UI. I really do not know. #### Hardcoded 'github.com' in source code - `KogitoMenu.tsx` - `href="https://github.com/settings/tokens"` - `OpenInExternalEditorButton.tsx` - `return `https://github.com/${prInfo.org}/${prInfo.repo}/tree/${prInfo.gitRef}`;` not sure if we can overcome this somehow using chrome API to replace those dinamically, bellow is example how to get URL via chrome API ``` chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => { let url = tabs[0].url; // use `url` here inside the callback because it's asynchronous! }); ``` ### Solution One I replaced this manifest configuration: ``` "content_scripts": [ { "run_at": "document_idle", "js": ["content_scripts/github.js"], "matches": ["https://*.github.com/*"], "all_frames": true } ], ``` with this code in `background.ts`: ``` chrome.action.onClicked.addListener((tab) => { if (!tab.url?.includes('chrome://')) { chrome.scripting.executeScript({ target: { tabId: tab.id ?? 0 }, files: ["content_scripts/github.js"], }); } }); ``` and added `"activeTab", "scripting"` permissions into manifest The resulting effect is, that the 'Open in KIE Sandbox' button appears only, once user clicks the extension icon:   ### Solution Two Was to change manifest content_scripts match section to be 'allow all' ``` "content_scripts": [ { "run_at": "document_idle", "js": ["content_scripts/github.js"], "matches": ["https://*/*", "http://*/*"], "all_frames": true } ], ``` What then brings this default setting in chrome extension:  ^ what is really not idea, but can be changed to:  ^ what makes user responsible for setting only appropriate github instances there -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
