Why don't javascript: URLs work from extensions on Safari? - safari-extension

I'm building a Safari extensions that fakes a POST by dynamically creating a form using a javascript: URL.
When I try to load this URL like this:
tab.url = "javascript:" + foo;
I get "Safari can't use JavaScript for this action"
I tried doing something simple like:
tab.url = "javascript:alert('hello')";
and I get the same error.
I tried pasting my URL directly into the URL bar and it works fine.
Is there any reason Safari doesn't allow extensions to load javacript: URLs? OR is there some workaround?

To answer my own question, you can use a data URL instead:
data:text/html,<body></body><script>alert('hello');</script>
Works just as well as the javascript: URL. You need to make sure you include the body, though, just in case your bookmarklet depends on there being a body.
I still don't know why javascript: URLs work in from Safari extensions, though.

Related

How can I add a url (live chat) in a vuejs website?

I've tried different kinds of embeds on my website but it doesnt seem to work. Can I still add a url and show it inside a vuejs website?
Yes we can use. The approach is iframe tag as
<iframe
src="url of live chat"></iframe>
Please use it

Display an internal link URL on a page/article with Pelican

The usual syntax to make links with Pelican is:
This is [a link]({filename}/foo.md)
That works just fine.
But I'm on a page where I'd like to actually show the URL of the link. That is, I want the generated HTML to be like this:
<p>Here is the link:</p>
https://example.com/foo.html
I tried writing the obvious:
[{filename}/foo.md]({filename}/foo.md)
But that got rendered as:
{filename}/foo.md
I couldn't find anything in the documentation, is there any way to do that?
I don't think the feature in question was designed to behave that way. If it were me, I would use:
[https://example.com/foo.html]({filename}/foo.md)

How to rename thewire's URL in Elgg?

I have an install of ELGG, and I set up thewire. I hate the name thewire so I modified the language file, so it would look like posts.
When I looked at the URL on the posts page, it still said http://localhost/thewire, not http://localhost/posts. How would I make .htaccess change the URL to the desired effect.
I tried mod_rewrite, but I don't know what to do with it.
You need to do two things:
Change the URLs produced for thewire posts (register your own handler):
elgg_register_entity_url_handler('object', 'thewire', 'CUSTOM_HANDLER');
Handle new URL format instead of original one:
You may use 'route' plugin hook or try to use already existing plugin for that: http://community.elgg.org/plugins/854839/1.1/pagehandler-hijack-18x

Safari extension: how to get current url from injected script?

I am trying to get the current url from injected script but it seems impossible because of the permission.
From the official document, I got:
Injected scripts cannot access the SafariApplication or SafariExtension classes.
Is there any solution or w/a? Thanks.
Use window.location.href to get the URL of the page the script is injected into.
Scripts are injected into each iframe as well as the main page, so you might want to use a check like if (window == window.top) to if you are only interested in the main page.

Checking the contains of an embed tag using Selenium

We generate a pdf doc via a call to a web service that returns the path to the generated doc.
We use an embed html tag to display the pdf inline, i.e.
<div id="ctl00_ContentPlaceHolder2_ctl01_embedArea">
<embed wmode="transparent" src="http://www.company.com/vdir/folder/Pdfs/file.pdf" width="710" height="400"/>
I'd like to use selenium to check that the pdf is actually being displayed and if possible save the path, i.e. the src link into a variable.
Anyone know how to do this? Ideally we'd like to be able to then compare this pdf to a reference one but that's a question for another day.
As far as inspecting the pdf from selenium, you're more or less out of luck. The embed tag just drops a plugin into the page, and because a plugin isn't well represented in the DOM, Selenium can't get a very good handle on it.
However, if you're using Selenium-RC you may want to consider getting the src of the embed element, then requesting that URL directly and evaluating the resulting PDF in code. Assuming your embed element looks like this <embed id="embedded" src="http://example.com/static/pdf123.pdf" /> you can try something like this
String pdfSrc = selenium.getAttribute("embedded#src");
Then make a web request to the pdfSrc url and do (somehow) validate it's the one you want. It may be enough to just check that it's not a 404.