Skip to content
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

[Enhanced] Execute "javascript:" URLs by injecting them into the page itself. #3437

Merged
merged 3 commits into from
Dec 9, 2019
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
6 changes: 5 additions & 1 deletion background_scripts/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ do ->
TabOperations =
# Opens the url in the current tab.
openUrlInCurrentTab: (request) ->
chrome.tabs.update request.tabId, url: Utils.convertToUrl request.url
if Utils.hasJavascriptPrefix request.url
{tabId, frameId} = request
chrome.tabs.sendMessage tabId, {frameId, name: "executeScript", script: request.url}
else
chrome.tabs.update request.tabId, url: Utils.convertToUrl request.url

# Opens request.url in new tab and switches to it.
openUrlInNewTab: (request, callback = (->)) ->
Expand Down
1 change: 1 addition & 0 deletions content_scripts/vimium_frontend.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ initializePreDomReady = ->
NormalModeCommands[registryEntry.command] sourceFrameId, registryEntry if DomUtils.isTopFrame()
linkHintsMessage: (request) -> HintCoordinator[request.messageType] request
showMessage: (request) -> HUD.showForDuration request.message, 2000
executeScript: (request) -> DomUtils.injectUserScript request.script

chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
request.isTrusted = true
Expand Down
10 changes: 10 additions & 0 deletions lib/dom_utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ DomUtils =
style.textContent = Settings.get "userDefinedLinkHintCss"
document.head.appendChild style

# Inject user Javascript.
injectUserScript: (text) ->
if text[...11] == "javascript:"
text = text[11...].trim()
if text.indexOf(" ") < 0
try text = decodeURIComponent text
script = document.createElement "script"
script.textContent = text
document.head.appendChild script

root = exports ? (window.root ?= {})
root.DomUtils = DomUtils
extend window, root unless exports?