I'm trying to make my life easier at work with a Javascript Bookmarklet Search Engine in Chrome. The code runs but throws an error, which can be found below. I'm more than certain its the left and right apostrophes that are being used, but would be unsure on how to replace these (JS novice).
Any help would be much appreciated.
javascript: window.location.replace(‘https://force.com/one/one.app#'+btoa('{ “componentDef”: “forceSearch:searchPage”, “attributes”: { “term”: “‘+’%s’+’”, “scopeMap”: { “type”: “TOP_RESULTS” }, “context”: { “disableSpellCorrection”: false, “disableIntentQuery”: false, “permsAndPrefs”: { “SearchUi.searchUIPilotFeatureEnabled”: false, “SearchExperience.LeftNavEnhancementEnabled”: true, “Search.crossObjectsAutoSuggestEnabled”: true, “SearchResultsLVM.lvmEnabledForSearchResultsOn”: true, “MySearch.userCanHaveMySearchBestResult”: false, “SearchResultsLVM.lvmEnabledForTopResults”: false, “OrgPermissions.UnionAppNavSmartScope”: false, “SearchUi.feedbackComponentEnabled”: false, “SearchExperience.TopResultsSingleSOSLEnabled”: false, “OrgPreferences.ChatterEnabled”: true, “Search.maskSearchInfoInLogs”: false, “SearchUi.orgHasAccessToSearchTermHistory”: false, “SearchUi.searchUIInteractionLoggingEnabled”: false, “MySearch.userCanHaveMySearch”: false }, “searchDialogSessionId”:”00000000–0000–0000–0000–000000000000" , “searchSource”: “INPUT_DESKTOP” }, “groupId”: “DEFAULT” }, “state”: {} }’));
Error I received in Chrome's console:
Uncaught SyntaxError: Invalid or unexpected token
Edit: I just wanted to clarify that I have attempted to resolve this issue myself but online documentation does not clearly outline how I may go about encapsulating this single-line snippet. I have chosen to come to this website for a better explanation as to why I am doing this wrong and possible some source material so I could continue to improve my skillbase.
I have resolved the issue. I had fixed the first issue of it not running, but then encountered another issue where it wasn't encoding it correctly.
The main problem was that I didn't understand what I was doing, at all. It was a series of apostrophes included or missing.
For anyone who is interested, please see my revised code below, which works like a charm with Salesforce Lightning searches.
javascript: window.open('https://force.com/one/one.app#'+btoa(unescape(encodeURIComponent('{"componentDef":"forceSearch:searchPage","attributes":{"term":"%s","scopeMap":{"type":"TOP_RESULTS"},"context":{"disableSpellCorrection":false,"disableIntentQuery":false,"permsAndPrefs":{"SearchResultsLVM.lvmEnabledForSearchResultsOn":true},"searchDialogSessionId":"00000000–0000–0000–0000–000000000000","searchSource":"INPUT_DESKTOP"},"groupId":"DEFAULT"},"state":{}}'))));
Thanks all.