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:
   
   ![Screenshot 2024-01-11 
133654](https://github.com/apache/incubator-kie-issues/assets/8044780/4208db5d-b7e6-4ee1-89bd-fcca3e728834)
   ![Screenshot 2024-01-11 
133722](https://github.com/apache/incubator-kie-issues/assets/8044780/ce28a21a-254e-4e36-85fd-e3db72f7a3e0)
   
   ### 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:
   
![image](https://github.com/apache/incubator-kie-issues/assets/8044780/68496df1-f444-45c5-bfdd-1451bde491db)
   
   ^ what is really not idea, but can be changed to:
   ![Screenshot 2024-01-11 
134905](https://github.com/apache/incubator-kie-issues/assets/8044780/c2df198b-80de-4ca7-b142-e198d8a0982d)
   
   ^ 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]

Reply via email to