Skip to content

Replace 'IDE Key' terminology with 'Debug Trigger' #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const DEFAULT_IDE_KEY = 'PHPSTORM';
const DEFAULT_TRIGGER_VALUE = 'YOUR-NAME';

const getCookie = name =>
document.cookie.split(';').find(cookie => cookie.trim().startsWith(`${name}=`))?.split('=')[1];
Expand All @@ -7,9 +7,9 @@ const setCookie = (name, value, days = 365) =>
document.cookie = `${name}=${value};expires=${new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString()};path=/`;

const getStatusMap = (settings) => {
const { xdebugIdeKey, xdebugTraceTrigger, xdebugProfileTrigger } = settings;
const { xdebugDebugTrigger, xdebugTraceTrigger, xdebugProfileTrigger } = settings;
return {
1: { name: 'XDEBUG_SESSION', trigger: xdebugIdeKey },
1: { name: 'XDEBUG_SESSION', trigger: xdebugDebugTrigger },
2: { name: 'XDEBUG_PROFILE', trigger: xdebugProfileTrigger },
3: { name: 'XDEBUG_TRACE', trigger: xdebugTraceTrigger },
};
Expand All @@ -18,9 +18,9 @@ const getStatusMap = (settings) => {
const getCurrentStatus = () => {
return new Promise((resolve) => {
chrome.storage.local.get({
xdebugIdeKey: DEFAULT_IDE_KEY,
xdebugTraceTrigger: DEFAULT_IDE_KEY,
xdebugProfileTrigger: DEFAULT_IDE_KEY
xdebugDebugTrigger: DEFAULT_TRIGGER_VALUE,
xdebugTraceTrigger: DEFAULT_TRIGGER_VALUE,
xdebugProfileTrigger: DEFAULT_TRIGGER_VALUE
}, (settings) => {
const statusMap = getStatusMap(settings);
for (const [idx, { name, trigger }] of Object.entries(statusMap)) {
Expand All @@ -38,9 +38,9 @@ const getCurrentStatus = () => {
const setStatus = status => {
return new Promise((resolve) => {
chrome.storage.local.get({
xdebugIdeKey: DEFAULT_IDE_KEY,
xdebugTraceTrigger: DEFAULT_IDE_KEY,
xdebugProfileTrigger: DEFAULT_IDE_KEY
xdebugDebugTrigger: DEFAULT_TRIGGER_VALUE,
xdebugTraceTrigger: DEFAULT_TRIGGER_VALUE,
xdebugProfileTrigger: DEFAULT_TRIGGER_VALUE
}, (settings) => {
const statusMap = getStatusMap(settings);
for (const { name } of Object.values(statusMap)) {
Expand Down Expand Up @@ -70,4 +70,4 @@ chrome.runtime.onMessage.addListener((msg, _, res) => {
res({ status: 0 });
return true;
}
});
});
13 changes: 3 additions & 10 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ <h1>Xdebug Extension</h1>
<form>
<fieldset>
<legend>Options</legend>
<label for="idekey">IDE Key</label>
<input type="text" id="idekey" placeholder="IDE key" list="idekeys" value="">
<datalist id="idekeys">
<option value="PHPSTORM">PhpStorm</option>
<option value="XDEBUG_ECLIPSE">Eclipse</option>
<option value="netbeans-xdebug">NetBeans</option>
<option value="macgdbp">MacGDBp</option>
<option value="VSCODE">VSCode</option>
</datalist>
<label for="debugtrigger">Debug Trigger or Xdebug Cloud Key</label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "Xdebug Cloud Key" in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the key that you can use with https://xdebug.cloud — the cloud service uses the value of the same XDEBUG_SESSION cookie, to link that incoming HTTP/Xdebug connection with an IDE, that has registered with the cloud service with the same value.

It can also be set with the xdebug.cloud_id setting, but it's much easier to be able to set/override it through the session cookie, as this would allow every different developer (or rather, browser profile) to have their own connection.

<input type="text" id="debugtrigger" placeholder="Debug trigger or Xdebug Cloud Key" value="YOUR-NAME">
<label for="tracetrigger">Trace Trigger</label>
<input type="text" id="tracetrigger" placeholder="Trace trigger" value="">
<label for="profiletrigger">Profile Trigger</label>
Expand All @@ -40,4 +33,4 @@ <h2>Shortcuts</h2>
<script src="options.js"></script>
</body>

</html>
</html>
12 changes: 6 additions & 6 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
document.addEventListener('DOMContentLoaded', () => {
const optionsForm = document.querySelector('form');
const ideKeyInput = document.getElementById('idekey');
const debugTriggerInput = document.getElementById('debugtrigger');
const traceTriggerInput = document.getElementById('tracetrigger');
const profileTriggerInput = document.getElementById('profiletrigger');
const helpDiv = document.getElementById('help');

document.querySelector('button[type="reset"]').addEventListener('click', e => {
e.preventDefault();
ideKeyInput.value = '';
debugTriggerInput.value = '';
traceTriggerInput.value = '';
profileTriggerInput.value = '';
});

document.querySelector('button[type="submit"]').addEventListener('click', e => {
e.preventDefault();
chrome.storage.local.set({
xdebugIdeKey: ideKeyInput.value,
xdebugDebugTrigger: debugTriggerInput.value,
xdebugTraceTrigger: traceTriggerInput.value,
xdebugProfileTrigger: profileTriggerInput.value
});
Expand All @@ -24,11 +24,11 @@ document.addEventListener('DOMContentLoaded', () => {
});

chrome.storage.local.get({
xdebugIdeKey: 'PHPSTORM',
xdebugDebugTrigger: 'YOUR-NAME',
xdebugTraceTrigger: null,
xdebugProfileTrigger: null,
}, (settings) => {
ideKeyInput.value = settings.xdebugIdeKey;
debugTriggerInput.value = settings.xdebugDebugTrigger;
traceTriggerInput.value = settings.xdebugTraceTrigger;
profileTriggerInput.value = settings.xdebugProfileTrigger;
});
Expand Down Expand Up @@ -62,4 +62,4 @@ document.addEventListener('DOMContentLoaded', () => {
helpDiv.appendChild(newP);
}
});
});
});
18 changes: 9 additions & 9 deletions src/service_worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const DEFAULT_IDE_KEY = 'PHPSTORM';
const DEFAULT_TRIGGER_VALUE = 'YOUR-NAME';

const getSettings = async () => {
return new Promise((resolve, reject) => {
chrome.storage.local.get({
xdebugIdeKey: DEFAULT_IDE_KEY,
xdebugTraceTrigger: DEFAULT_IDE_KEY,
xdebugProfileTrigger: DEFAULT_IDE_KEY
xdebugDebugTrigger: DEFAULT_TRIGGER_VALUE,
xdebugTraceTrigger: DEFAULT_TRIGGER_VALUE,
xdebugProfileTrigger: DEFAULT_TRIGGER_VALUE
}, (settings) => {
if (chrome.runtime.lastError) {
return reject(new Error(chrome.runtime.lastError));
Expand Down Expand Up @@ -42,10 +42,10 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
}

try {
const { xdebugIdeKey, xdebugTraceTrigger, xdebugProfileTrigger } = await getSettings();
const { xdebugDebugTrigger, xdebugTraceTrigger, xdebugProfileTrigger } = await getSettings();
const response = await chrome.tabs.sendMessage(tabId, {
cmd: 'getStatus',
idekey: xdebugIdeKey,
debugTrigger: xdebugDebugTrigger,
traceTrigger: xdebugTraceTrigger,
profileTrigger: xdebugProfileTrigger
});
Expand All @@ -66,7 +66,7 @@ chrome.commands.onCommand.addListener(async (command) => {
const settings = await getSettings();
const response = await chrome.tabs.sendMessage(tab.id, {
cmd: 'getStatus',
idekey: settings.xdebugIdeKey,
debugTrigger: settings.xdebugDebugTrigger,
traceTrigger: settings.xdebugTraceTrigger,
profileTrigger: settings.xdebugProfileTrigger
});
Expand All @@ -90,7 +90,7 @@ chrome.commands.onCommand.addListener(async (command) => {
const setResponse = await chrome.tabs.sendMessage(tab.id, {
cmd: 'setStatus',
status: newState,
idekey: settings.xdebugIdeKey,
debugTrigger: settings.xdebugDebugTrigger,
traceTrigger: settings.xdebugTraceTrigger,
profileTrigger: settings.xdebugProfileTrigger
});
Expand All @@ -115,7 +115,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
const response = await chrome.tabs.sendMessage(tab.id, {
cmd: 'setStatus',
status: request.status,
idekey: settings.xdebugIdeKey,
debugTrigger: settings.xdebugDebugTrigger,
traceTrigger: settings.xdebugTraceTrigger,
profileTrigger: settings.xdebugProfileTrigger
});
Expand Down
18 changes: 9 additions & 9 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Ensure you have the following prerequisites installed:
```bash
sudo apt update
sudo apt upgrade
sudo apt install nodejs
sudo apt install nodejs
sudo snap install chromium
```

Expand Down Expand Up @@ -46,7 +46,7 @@ Upon successful execution, you should see output similar to this:
Options Tests
✓ Should render options correctly (552 ms)
✓ Should render default shortcuts correctly (621 ms)
✓ Should set IDE Key correctly and save (559 ms)
✓ Should set Debug Trigger correctly and save (559 ms)
✓ Should set Trace Trigger correctly and save (561 ms)
✓ Should set Profile Trigger correctly and save (552 ms)
✓ Should clear all text inputs when the clear button is clicked (489 ms)
Expand Down Expand Up @@ -74,7 +74,7 @@ You can customize the test execution using the following environment variables.

`BROWSER_PATH` Specifies the path to the browser executable. Defaults to `/snap/bin/chromium`.
```bash
BROWSER_PATH=/usr/bin/google-chrome npm test
BROWSER_PATH=/usr/bin/google-chrome npm test
```
---

Expand All @@ -84,9 +84,9 @@ EXAMPLE_PAGE=https://example.com/ npm test
```
---

`DEFAULT_KEY` Configures the default IDE key for the Xdebug extension. Defaults to `PHPSTORM`.
`DEFAULT_TRIGGER_VALUE` Configures the default trigger value key for the Xdebug extension. Defaults to `YOUR-NAME`.
```bash
DEFAULT_KEY=MY_CUSTOM_KEY npm test
DEFAULT_TRIGGER_VALUE=MY_CUSTOM_KEY npm test
```
---

Expand Down Expand Up @@ -118,20 +118,20 @@ DEV_TOOLS=true npm test

### Browser was not found at the configured executablePath

Please verify that a compatible browser (like Chromium) is installed and accessible.
Please verify that a compatible browser (like Chromium) is installed and accessible.

The expected default location is `/snap/bin/chromium`.

If your browser is installed elsewhere, set the `BROWSER_PATH` environment variable before running the tests. For example:
If your browser is installed elsewhere, set the `BROWSER_PATH` environment variable before running the tests. For example:

```bash
BROWSER_PATH=/path/to/your/browser npm test
```

### Failed to launch the browser process! Missing X server or $DISPLAY

If you are using a non-GUI distribution, such as in WSL/WSL2, you will need to set the `DISPLAY` environment variable. You can do this using the command:
If you are using a non-GUI distribution, such as in WSL/WSL2, you will need to set the `DISPLAY` environment variable. You can do this using the command:

```bash
export DISPLAY=:0
```
```
16 changes: 8 additions & 8 deletions test/__TEST__/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Options Tests', () => {
const options = await openOptions();

// Assert
await expect(options.$('#idekey')).resolves.not.toBeNull(); // IDE Key
await expect(options.$('#debugtrigger')).resolves.not.toBeNull(); // Debug Trigger
await expect(options.$('#tracetrigger')).resolves.not.toBeNull(); // Trace Trigger
await expect(options.$('#profiletrigger')).resolves.not.toBeNull(); // Profile Trigger
await expect(options.$('button[type="reset"]')).resolves.not.toBeNull(); // Clear
Expand Down Expand Up @@ -45,18 +45,18 @@ describe('Options Tests', () => {
});


test('Should set IDE Key correctly and save', async () => {
test('Should set Debug Trigger correctly and save', async () => {
// Arrange
const options = await openOptions();

// Act
const key = 'IDE_KEY_TEST';
await options.locator('#idekey').fill(key);
const key = 'DEBUG_TRIGGER_TEST';
await options.locator('#debugtrigger').fill(key);
await options.locator('button[type="submit"]').click();

// Assert
await options.waitForSelector('form.success');
const storedValue = await waitForStoredValue(options, 'xdebugIdeKey');
const storedValue = await waitForStoredValue(options, 'xdebugDebugTrigger');
expect(storedValue).toBe(key);
await options.close();
});
Expand Down Expand Up @@ -99,15 +99,15 @@ describe('Options Tests', () => {
const options = await openOptions();

// Act
await options.locator('#idekey').fill('foo');
await options.locator('#debugtrigger').fill('foo');
await options.locator('#tracetrigger').fill('bar');
await options.locator('#profiletrigger').fill('bat');
await options.click('button[type="reset"]');

// Assert
await expect(options.$eval('#idekey', el => el.value)).resolves.toBe('');
await expect(options.$eval('#debugtrigger', el => el.value)).resolves.toBe('');
await expect(options.$eval('#tracetrigger', el => el.value)).resolves.toBe('');
await expect(options.$eval('#profiletrigger', el => el.value)).resolves.toBe('');
await options.close();
});
});
});
4 changes: 2 additions & 2 deletions test/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module.exports = {
extensionDir: '../src',
browserPath: process.env.BROWSER_PATH || '/snap/bin/chromium',
examplePage: process.env.EXAMPLE_PAGE || 'http://localhost:8765',
defaultKey: process.env.DEFAULT_KEY || 'PHPSTORM',
defaultKey: process.env.DEFAULT_TRIGGER_VALUE || 'YOUR-NAME',
timeout: process.env.TIMEOUT || 3000,
slowMo: process.env.SLOW_MO || 0,
devtools: process.env.DEV_TOOLS || false,
headless: process.env.HEADLESS === 'false' ? false : true,
}
}
};
};