Skip to content

Commit 7e817ac

Browse files
Copilotdevm33
andcommitted
Improve error handling and user feedback in content script
Co-authored-by: devm33 <1682753+devm33@users.noreply.github.com>
1 parent 39bdf6e commit 7e817ac

3 files changed

Lines changed: 411 additions & 9 deletions

File tree

TESTING.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Testing & Verification Guide
2+
3+
## Extension Verification Checklist
4+
5+
### Installation Verification
6+
- [ ] Extension loads without errors in Chrome
7+
- [ ] Extension icon appears in Chrome toolbar
8+
- [ ] No errors in Chrome DevTools console
9+
- [ ] Extension shows as active in `chrome://extensions/`
10+
11+
### Feature 1: Copy PR Link Button
12+
**Test Scenarios:**
13+
14+
1. **Regular PR (Open)**
15+
- Navigate to: Any open GitHub pull request
16+
- Expected: "Copy PR Link" button appears next to PR title
17+
- Action: Click the button
18+
- Expected:
19+
- Text copied to clipboard in format: `{PR Title}: {PR URL}`
20+
- Button shows "Copied!" with green checkmark
21+
- Button returns to normal state after 2 seconds
22+
23+
2. **Draft PR**
24+
- Navigate to: Any draft GitHub pull request
25+
- Expected: Same behavior as regular PR for Feature 1
26+
27+
3. **Closed/Merged PR**
28+
- Navigate to: A closed or merged pull request
29+
- Expected: Same behavior - button should still work
30+
31+
### Feature 2: Request Copilot Review Button
32+
**Test Scenarios:**
33+
34+
1. **Draft PR with Copilot Available**
35+
- Navigate to: A draft pull request where Copilot is available
36+
- Expected: "Request Review" button appears next to Copilot reviewer link
37+
- Action: Click the button
38+
- Expected:
39+
- Attempts to open reviewer selection UI
40+
- Button shows "Requested!" with green checkmark
41+
- Button returns to normal state after 2 seconds
42+
43+
2. **Non-Draft PR**
44+
- Navigate to: An open (non-draft) pull request
45+
- Expected: "Request Review" button does NOT appear
46+
- Reason: Feature only activates on draft PRs
47+
48+
3. **Draft PR without Copilot**
49+
- Navigate to: A draft PR where Copilot is not listed as a reviewer option
50+
- Expected: Button does not appear (no Copilot link to attach to)
51+
52+
### Cross-Browser Testing
53+
- [ ] Chrome (primary target)
54+
- [ ] Microsoft Edge (Chromium-based)
55+
- [ ] Brave (Chromium-based)
56+
57+
### Edge Cases
58+
- [ ] Button positioning is correct and doesn't break layout
59+
- [ ] Buttons don't duplicate on dynamic page updates
60+
- [ ] Extension works with GitHub's dark and light themes
61+
- [ ] Extension works on private repositories
62+
- [ ] Extension works on organization repositories
63+
- [ ] Copy function works correctly with special characters in PR title
64+
- [ ] Extension doesn't interfere with other GitHub functionality
65+
66+
## Manual Test Results
67+
68+
### Test Environment
69+
- Browser: _____________
70+
- Browser Version: _____________
71+
- Date Tested: _____________
72+
- Tester: _____________
73+
74+
### Feature 1 Results
75+
| Test Case | Status | Notes |
76+
|-----------|--------|-------|
77+
| Button appears | ⬜ Pass / ⬜ Fail | |
78+
| Copy to clipboard works | ⬜ Pass / ⬜ Fail | |
79+
| Format is correct | ⬜ Pass / ⬜ Fail | |
80+
| Visual feedback works | ⬜ Pass / ⬜ Fail | |
81+
82+
### Feature 2 Results
83+
| Test Case | Status | Notes |
84+
|-----------|--------|-------|
85+
| Button appears on draft PR | ⬜ Pass / ⬜ Fail | |
86+
| Button hidden on non-draft PR | ⬜ Pass / ⬜ Fail | |
87+
| Click action works | ⬜ Pass / ⬜ Fail | |
88+
| Visual feedback works | ⬜ Pass / ⬜ Fail | |
89+
90+
## Troubleshooting
91+
92+
### Extension not loading
93+
1. Check that Developer mode is enabled in `chrome://extensions/`
94+
2. Verify all files (manifest.json, content.js, icons) are present
95+
3. Check for errors in the Extensions page
96+
4. Try removing and re-adding the extension
97+
98+
### Buttons not appearing
99+
1. Open DevTools console (F12) and check for JavaScript errors
100+
2. Verify you're on a GitHub pull request page (URL: github.com/*/*/pull/*)
101+
3. Refresh the page
102+
4. Check if GitHub has changed their DOM structure (selectors might need updating)
103+
104+
### Copy to clipboard not working
105+
1. Check browser permissions for clipboard access
106+
2. Try on a different GitHub PR page
107+
3. Check DevTools console for errors
108+
4. Ensure the page is loaded over HTTPS
109+
110+
### Request Review button not working
111+
1. Verify the PR is actually in draft status
112+
2. Check that Copilot reviewer is available on the repository
113+
3. Check DevTools console for errors
114+
4. May need to manually adjust based on GitHub's current UI structure
115+
116+
## Debugging Tips
117+
118+
### View Extension Console Logs
119+
1. Go to `chrome://extensions/`
120+
2. Find "GitHub UI Mods"
121+
3. Click "Inspect views: background page" or inspect the content script from DevTools
122+
123+
### Inspect Content Script
124+
1. Open any GitHub PR page
125+
2. Open DevTools (F12)
126+
3. Go to Console tab
127+
4. Look for messages from the extension
128+
5. Use Sources tab to set breakpoints in content.js
129+
130+
### Test on Local HTML
131+
1. Open `test.html` in your browser
132+
2. Verify buttons appear on the simulated GitHub page
133+
3. This tests the extension logic without needing actual GitHub access
134+
135+
## Known Limitations
136+
137+
1. **Request Review functionality**: This feature attempts to automate clicking through GitHub's UI. If GitHub changes their DOM structure, this may break and require updates to the selectors in content.js.
138+
139+
2. **Dynamic content**: GitHub uses dynamic content loading. The extension uses MutationObserver to handle this, but there may be edge cases where buttons don't appear immediately.
140+
141+
3. **Permissions**: The extension only has access to GitHub pull request pages (for security and performance).
142+
143+
## Reporting Issues
144+
145+
If you encounter issues:
146+
1. Check the Troubleshooting section above
147+
2. Document the issue with:
148+
- Browser and version
149+
- GitHub page URL (without sensitive info)
150+
- Steps to reproduce
151+
- Console errors (if any)
152+
- Screenshots (if applicable)

content.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
const textToCopy = `${prTitle}: ${prUrl}`;
4242

4343
// Copy to clipboard
44+
// Save original button content before try/catch
45+
const originalText = button.innerHTML;
4446
try {
4547
await navigator.clipboard.writeText(textToCopy);
4648

4749
// Visual feedback
48-
const originalText = button.innerHTML;
4950
button.innerHTML = `
5051
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" style="display:inline-block;vertical-align:text-bottom;">
5152
<path fill="currentColor" d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path>
@@ -60,9 +61,17 @@
6061
}, 2000);
6162
} catch (err) {
6263
console.error('Failed to copy:', err);
63-
button.textContent = 'Failed to copy';
64+
button.innerHTML = `
65+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" style="display:inline-block;vertical-align:text-bottom;">
66+
<path fill="currentColor" d="M9.036 7.976a.75.75 0 0 0-1.06 1.06L10.939 12l-2.963 2.963a.75.75 0 1 0 1.06 1.06L12 13.06l2.963 2.964a.75.75 0 0 0 1.061-1.06L13.061 12l2.963-2.964a.75.75 0 0 0-1.06-1.06L12 10.939 9.036 7.976Z"></path>
67+
<path fill="currentColor" d="M12 1c6.075 0 11 4.925 11 11s-4.925 11-11 11S1 18.075 1 12 5.925 1 12 1ZM2.5 12a9.5 9.5 0 0 0 9.5 9.5 9.5 9.5 0 0 0 9.5-9.5A9.5 9.5 0 0 0 12 2.5 9.5 9.5 0 0 0 2.5 12Z"></path>
68+
</svg>
69+
Failed
70+
`;
71+
button.style.color = '#f85149';
6472
setTimeout(() => {
6573
button.innerHTML = originalText;
74+
button.style.color = '';
6675
}, 2000);
6776
}
6877
});
@@ -116,28 +125,36 @@
116125
button.addEventListener('click', async function(e) {
117126
e.preventDefault();
118127

119-
// Find the review request form/button
128+
// Save original button content
129+
const originalText = button.innerHTML;
130+
131+
// Try to find the review request form/button
120132
// GitHub's UI typically has a button or action to request reviews
121133
// We'll try to find and click it programmatically
122134

123135
// Try to find the "Reviewers" section and expand it if needed
124136
const reviewersSection = document.querySelector('.discussion-sidebar-item.js-discussion-sidebar-item');
125137
if (reviewersSection) {
126-
const requestReviewBtn = reviewersSection.querySelector('button[aria-label*="request"]');
138+
// Try multiple selector patterns for the request review button
139+
const requestReviewBtn = reviewersSection.querySelector('button[aria-label*="request"]') ||
140+
reviewersSection.querySelector('summary[aria-label*="request"]') ||
141+
reviewersSection.querySelector('.js-request-reviewers-button');
142+
127143
if (requestReviewBtn) {
128144
requestReviewBtn.click();
129145

130146
// Wait a bit for the modal/dropdown to appear
131147
setTimeout(() => {
132148
// Try to find and click on Copilot in the reviewer list
133-
const copilotReviewerOption = document.querySelector('[data-filterable-for*="copilot"]');
149+
const copilotReviewerOption = document.querySelector('[data-filterable-for*="copilot"]') ||
150+
document.querySelector('[data-targets*="copilot"]') ||
151+
document.querySelector('label[for*="copilot"]');
134152
if (copilotReviewerOption) {
135153
copilotReviewerOption.click();
136154
}
137155
}, 100);
138156

139-
// Visual feedback
140-
const originalText = button.innerHTML;
157+
// Visual feedback - success
141158
button.innerHTML = `
142159
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" style="display:inline-block;vertical-align:text-bottom;">
143160
<path fill="currentColor" d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path>
@@ -152,10 +169,35 @@
152169
}, 2000);
153170
} else {
154171
// Fallback: provide feedback that manual action is needed
155-
alert('Please request the review manually from the Reviewers section');
172+
button.innerHTML = `
173+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" style="display:inline-block;vertical-align:text-bottom;">
174+
<path fill="currentColor" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
175+
</svg>
176+
Use Reviewers section
177+
`;
178+
button.style.color = '#db6d28';
179+
button.title = 'Could not find review request button. Please use the Reviewers section manually.';
180+
setTimeout(() => {
181+
button.innerHTML = originalText;
182+
button.style.color = '';
183+
button.title = 'Request Copilot review for draft PR';
184+
}, 3000);
156185
}
157186
} else {
158-
alert('Could not find Reviewers section. Please request the review manually.');
187+
// Could not find reviewers section
188+
button.innerHTML = `
189+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" style="display:inline-block;vertical-align:text-bottom;">
190+
<path fill="currentColor" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
191+
</svg>
192+
Use Reviewers section
193+
`;
194+
button.style.color = '#db6d28';
195+
button.title = 'Could not find Reviewers section. Please request review manually.';
196+
setTimeout(() => {
197+
button.innerHTML = originalText;
198+
button.style.color = '';
199+
button.title = 'Request Copilot review for draft PR';
200+
}, 3000);
159201
}
160202
});
161203

0 commit comments

Comments
 (0)