I've worked over the past few days to namespace/modularize my code and have been working almost exlusively in Chrome. When I stepped back tonight to test in other browsers, Firefox works fine but Safari is dead in the water (no idea on IE yet). Am wondering why my popup's JavaScript isn't getting executed in Safari.
My crossriderMain function looks like this:
function crossriderMain($) {
appAPI.resources.includeCSS("styles/popup.css");
eval(appAPI.resources.get("scripts/popup.js"));
}
I've posted scripts/popup.js at https://gist.github.com/aaitken/18e98... - while it's 135 lines longs, I'm hoping there's an architectural gotcha that pops out at someone above the weeds.
Thanks!
Help get this topic noticed by sharing it on
Twitter,
Facebook, or email.
Twitter,
Facebook, or email.
Why is my popup's crossriderMain function able to pull in css but not execute my javascript in Safari?
-
Hello Alexander,
I understand that you are having an issue with your code in Safari. Usually, this works without problems and I suggest you check that you have followed the scoping issues with Safari as mentioned in appAPI.ready.
If you require further assistance, I need to take a closer look and therefore please provide as much of the following information as possible and I will investigate:
- The extension id
- The file/line number where the code snippet can be found
- Which browser and operating system you are testing on, including version numbers
- The exact steps for reproducing the problem
- Any additional useful data, such as URLs, screenshots, videos, ...
-
-
Thanks for your reply, Shlomo.
extension id: 72574
file: Resources/scripts/popup.js
browser/os: safari 8.0.3 / osx 10.10.2
steps: install extension > click icon
expected behavior (confirmed in other browsers): radio buttons (first in each group) are auto-selected and basic red css color theme is applied to page text
actual behavior: zilch
I saw the note on Safari's scoping issue; does this apply to js in the popup? I used the example at https://crossrider.com/apps/24802/ide as a starting point but don't see crossriderMain (in popup.html) invoking appAPI.ready. -
-
Hello Alexander,
Firstly, for all intents and purposes crossriderMain is equivalent to appAPI.ready (not that appAPI.ready is called from within crossriderMain but has similar behavior).
I notice that in popup.js you are declaring variables outside the scope of the IIFEs you are using. It's possibly this that causing your issues. Try passing the variables into you IIFEs and see if it resolves your problem. -
-
Thanks again for your help and ideas. At the end of the day, it turned out that the problem was with the $(document).ready call that I had within crossriderMain. I assumed this was necessary since I had dom-manipulating code in the document's head section. Once I got rid of this, however, and put all code straight within crossriderMain all was well.
Does crossriderMain implement a doc.ready equivalent or is it simple (and unreliable) chance that its code executes once subsequent dom elements are in place? What are recommended best practices here? -
-
Hello Alexander,
Yes, the doc.ready equivalent is called crossriderMain in popups and appAPI.ready in extension.js files :) -
-
-
Loading Profile...




EMPLOYEE

