This repo is forked from chrisputnam9/chrome-google-keep-full-screen. This document details the modifications made to the Google Keep Full Screen extension to make it compatible with Electron. Since this is now a fork of the original extension hosted at samlam369/chrome-google-keep-full-screen, this information will help future maintainers understand the changes and maintain them when merging upstream updates.
Electron provides Chrome extension API compatibility, but there are some differences in how these APIs behave compared to a regular Chrome browser:
- Availability of Chrome APIs: Some Chrome APIs may not be fully available or might behave differently in Electron.
- Error Handling: The extension needs robust error handling to gracefully handle cases where Chrome APIs are absent or fail.
- DOM Element Availability: The extension needs to check for element existence before attaching observers or event listeners.
The init() function has been wrapped in a try/catch block to prevent initialization failures from crashing the entire extension:
init: async function () {
try {
// Original initialization code
...
} catch (err) {
console.error('Extension initialization error:', err);
}
},The Chrome storage API calls are wrapped in try/catch blocks with fallbacks:
// Original code
const storage = await promise_chrome_storage_sync_get(["settings"]);
// Modified code
try {
const storage = await promise_chrome_storage_sync_get(["settings"]);
if ("settings" in storage && "fullscreen" in storage.settings) {
this.fullscreen = storage.settings.fullscreen;
}
} catch (storageErr) {
// Chrome storage may not be available in Electron
console.log('Chrome storage API error:', storageErr);
// Continue with default fullscreen setting
}Chrome messaging is wrapped in try/catch to handle potential unavailability:
// Original code
chrome.runtime.onMessage.addListener(function (request) {
// Handle keyboard shortcuts
...
});
// Modified code
try {
chrome.runtime.onMessage.addListener(function (request) {
// Handle keyboard shortcuts
...
});
} catch (chromeErr) {
// Chrome messaging may not be available in Electron
console.log('Chrome messaging API error:', chromeErr);
}Added checks for element existence before attaching observers:
// Original code
main.observerNewNotes.observe(elCreatedNotesGroupContainer, {
childList: true,
});
// Modified code
if (elCreatedNotesGroupContainer) {
main.observerNewNotes.observe(elCreatedNotesGroupContainer, {
childList: true,
});
} else {
console.log('Note container not found, observer not attached');
}The promise_chrome_storage_sync_set and promise_chrome_storage_sync_get methods have been modified to handle errors gracefully:
// Original
function promise_chrome_storage_sync_get(data) {
return new Promise((resolve, reject) => {
try {
chrome.storage.sync.get(data, resolve);
} catch (error) {
reject(error);
}
});
}
// Modified
function promise_chrome_storage_sync_get(data) {
return new Promise((resolve, reject) => {
try {
chrome.storage.sync.get(data, resolve);
} catch (error) {
console.log("chrome.storage.sync.get error:", error);
// Return empty object to prevent errors in Electron
resolve({});
}
});
}The options menu click handler is also wrapped in a try/catch:
// Original
elMenuItemOptions.addEventListener("click", function (event) {
event.preventDefault();
chrome.runtime.sendMessage({ action: "open-options" });
});
// Modified
elMenuItemOptions.addEventListener("click", function (event) {
event.preventDefault();
try {
chrome.runtime.sendMessage({ action: "open-options" });
} catch (error) {
console.log("Chrome runtime sendMessage error:", error);
}
});As this is now a fork maintained at samlam369/chrome-google-keep-full-screen, changes from the upstream repository should be manually merged into this fork. When merging upstream changes:
- Pull the upstream changes into a separate branch
- Review the changes, particularly any modifications to
script.js - Manually merge the changes while preserving the error handling modifications
- Run the app to test that the extension still works correctly in Electron
The Electron app expects the extension's manifest.json to be present and properly configured in the root of this directory. For compatibility and to ensure the extension loads correctly:
- The
manifest.jsonis copied frompublish/manifest-chrome.json(or created from the latest upstream manifest if needed). - The
run_atproperty for the content script must be set to"document_idle". - If you update the manifest or pull changes from upstream, always verify that
run_atis still set correctly inmanifest.json. - This ensures that the extension is injected at the appropriate time for Google Keep to function correctly in Electron.
If you make changes to the manifest or update the extension, make sure to check this property before running or distributing the app.
After making any changes to the extension code, test the following functionality:
- Opening the app and ensuring the extension loads
- Creating and opening a note to verify the full-screen functionality works
- Toggling full-screen mode using the button in the note toolbar
- Testing any keyboard shortcuts defined by the extension
By maintaining our own fork with these compatibility changes, we ensure the extension will continue to work reliably in our Electron application while still allowing us to incorporate improvements from the upstream repository.