diff --git a/src/common.css b/src/common.css index 9218ea4..b1db620 100644 --- a/src/common.css +++ b/src/common.css @@ -5,3 +5,7 @@ .ob-input { @apply block m-1.5 p-2 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500; } + +.ob-input-error { + @apply bg-red-50 border-red-500 text-red-900 placeholder-red-700 focus:ring-red-500 focus:border-red-500; +} diff --git a/src/options.ts b/src/options.ts index bd0604c..6cdfc72 100644 --- a/src/options.ts +++ b/src/options.ts @@ -11,7 +11,19 @@ chrome.storage.sync.get(null, (data) => { input.value = cssSelectors[i] || "" input.addEventListener("change", (event) => { if (event.target instanceof HTMLInputElement) { - cssSelectors[i] = event.target.value + const value = event.target.value.trim() + if (value !== "") { + // Validate target value + try { + document.querySelectorAll(value) + } catch (error: unknown) { + event.target.classList.add("ob-input-error") + console.info("OpenBlur invalid CSS selector:", value, error) + return + } + } + event.target.classList.remove("ob-input-error") + cssSelectors[i] = value void chrome.storage.sync.set({ cssSelectors }) // Send message to content script in all tabs void chrome.tabs diff --git a/static/options.html b/static/options.html index 70a46e6..9685e3a 100644 --- a/static/options.html +++ b/static/options.html @@ -8,15 +8,15 @@