through.a.haze
through.a.haze

Reputation: 526

Can I use PHP scripts in Firefox extension?

If I put PHP script in the "data" directory can I use it in my Firefox add-on?

Upvotes: 2

Views: 961

Answers (2)

Calvin Kwok
Calvin Kwok

Reputation: 161

Firefox CANNOT use php in extension directly, unless you indirectly call your php code via XPCOM or other workaround.

Upvotes: 1

kapex
kapex

Reputation: 29959

Firefox add-ons can only execute JavaScript. This still leaves you with a few options:

  • Rewrite the PHP code in javascript by hand
  • Rewrite the PHP code in javascript by hand, using a library like phpjs which emulate PHPfunctions in javascript
  • Use a PHP-to-JavaScript transpiler to convert the code (might only work for simple code)
  • use a PHP interpreter that is written in JavaScript, like this one and execute the PHP script

(I just googled those links and have no idea how well they work, there probably are better alternatives)

A rewrite of the PHP code is the only clean way in my opinion. Carefully migrating the most basic code with a transpiler might save some time though.

Upvotes: 3

Related Questions